{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The autoreload extension is already loaded. To reload it, use:\n",
      "  %reload_ext autoreload\n"
     ]
    }
   ],
   "source": [
    "%matplotlib notebook\n",
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "import load_files\n",
    "import models\n",
    "from load_files import *\n",
    "from models import *\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(7352, 128, 9) (7352, 1)\n",
      "(2947, 128, 9) (2947, 1)\n",
      "(7352, 128, 9) (7352, 6) (2947, 128, 9) (2947, 6)\n"
     ]
    }
   ],
   "source": [
    "x_train, y_train, x_test, y_test = load_dataset('../data/HAR/UCI_HAR_Dataset/')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0., 0., 0., 0., 1., 0.],\n",
       "       [0., 0., 0., 0., 1., 0.],\n",
       "       [0., 0., 0., 0., 1., 0.],\n",
       "       ...,\n",
       "       [0., 1., 0., 0., 0., 0.],\n",
       "       [0., 1., 0., 0., 0., 0.],\n",
       "       [0., 1., 0., 0., 0., 0.]], dtype=float32)"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(7352, 128, 9)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_train.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "n_timesteps, n_features, n_outputs = x_train.shape[1], x_train.shape[2], y_train.shape[1]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "keras imports"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "from keras import Model\n",
    "from keras.layers import Lambda, Input, Dropout, Flatten, LSTM, Concatenate, Bidirectional, Conv1D\n",
    "from keras import backend as K\n",
    "from keras.callbacks import TensorBoard\n",
    "from time import time\n",
    "from keras import optimizers\n",
    "from keras.callbacks import ReduceLROnPlateau, EarlyStopping\n",
    "from time import time"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Model generators\n",
    "\n",
    "here we are going to analyse the performance of diffierent methods to classify the time series"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "here we define recall and auc metrics that are not implemented in keras\n",
    "\n",
    "references:\n",
    "\n",
    "https://stackoverflow.com/questions/41032551/how-to-compute-receiving-operating-characteristic-roc-and-auc-in-keras"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "import custom_metrics; from custom_metrics import as_keras_metric\n",
    "import tensorflow as tf\n",
    "\n",
    "auc_roc = as_keras_metric(tf.metrics.auc)\n",
    "recall = as_keras_metric(tf.metrics.recall)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Some callbacks\n",
    "\n",
    "we define some callbacks that we are going to implement during training\n",
    "\n",
    "https://stackoverflow.com/questions/50874596/how-to-detect-the-epoch-where-keras-earlystopping-occurred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "#lr_cb = ReduceLROnPlateau(monitor = 'val_loss', factor = 0.5, min_delta = 0.01, patience = 3, verbose = 1)\n",
    "#es_cb = EarlyStopping(monitor = 'val_loss', min_delta=0.01, patience = 10, verbose = 1, restore_best_weights = True)\n",
    "\n",
    "min_delta_val = 0.01\n",
    "lr_cb = ReduceLROnPlateau(monitor = 'val_auc', mode='max', \n",
    "                          factor = 0.5, min_delta = min_delta_val, patience = 3, verbose = 1)\n",
    "es_cb = EarlyStopping(monitor = 'val_auc', mode='max', \n",
    "                      min_delta=min_delta_val, patience = 10, verbose = 1, restore_best_weights = True)\n",
    "\n",
    "default_callbacks = [lr_cb, es_cb]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Training parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "from keras import optimizers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "N_train = 3\n",
    "adam = optimizers.adam(lr=0.01)\n",
    "validation_split_on_training = 0.2\n",
    "epochs = 60\n",
    "batch_size = 250"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "import models; from models import *\n",
    "\n",
    "def generate_trained_models(model_type):\n",
    "    \n",
    "    print_summary_only_once = True\n",
    "    trained_models = []\n",
    "    trained_models_best_epoch = []\n",
    "    trained_models_stats = []\n",
    "    trained_models_time_taken = []\n",
    "\n",
    "    model_name_base = model_type\n",
    "\n",
    "    if model_type =='dense_2':\n",
    "        model_generator = dense_1d_2_model_generator\n",
    "    elif model_type =='LSTM_2':\n",
    "        model_generator = lstm_model_2_generator\n",
    "    elif model_type =='dense':\n",
    "        model_generator = dense_1d_model_generator\n",
    "    elif model_type =='LSTM':\n",
    "        model_generator = lstm_model_generator\n",
    "    elif model_type =='ens':\n",
    "        model_generator = hybrid_ens_generator\n",
    "    elif model_type =='dense_fc':\n",
    "        model_generator = dense_fully_connected_model_generator        \n",
    "    elif model_type =='conv_1d':\n",
    "        model_generator = conv_1d_model_generator                \n",
    "    else:\n",
    "        raise ValueError('No model type found')\n",
    "    \n",
    "        \n",
    "    for i in range(N_train):\n",
    "        tic = time()\n",
    "        model_name = model_name_base + '_' + str(i)\n",
    "        tensorboard = TensorBoard(log_dir=\"logs/{}\".format(model_name + '_' + str(time())))\n",
    "        callbacks_model = default_callbacks + [tensorboard]\n",
    "\n",
    "        # generate model\n",
    "        model_input, model_output , _ = model_generator(n_timesteps, n_features, n_outputs)\n",
    "        model = Model(model_input, model_output, name = model_name)\n",
    "\n",
    "        #compile model\n",
    "        model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy', auc_roc, recall])\n",
    "        if print_summary_only_once:\n",
    "            model.summary()\n",
    "            print_summary_only_once = False\n",
    "\n",
    "        # train model\n",
    "        model.fit(x_train, \n",
    "                  y_train, epochs=epochs, \n",
    "                  batch_size=batch_size, \n",
    "                  validation_split=validation_split_on_training,\n",
    "                  verbose=True,\n",
    "                  shuffle=True,\n",
    "                  callbacks = callbacks_model)     \n",
    "        trained_models.append(model)\n",
    "\n",
    "        # training time\n",
    "        training_time = time()-tic\n",
    "        trained_models_time_taken.append(training_time)\n",
    "        print('training time: {}s'.format(training_time))\n",
    "\n",
    "        # early stopping epoch\n",
    "        best_epoch = es_cb.stopped_epoch\n",
    "        trained_models_best_epoch.append(best_epoch)\n",
    "\n",
    "        #append best stat\n",
    "        best_stats = {}\n",
    "        for key in model.history.history.keys():\n",
    "            best_stats[key] = model.history.history[key][best_epoch]\n",
    "        trained_models_stats.append(best_stats)\n",
    "    \n",
    "    trained_models_stats = pd.DataFrame(trained_models_stats)\n",
    "    return trained_models, trained_models_stats, trained_models_time_taken, trained_models_best_epoch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "input_5 (InputLayer)         (None, 128, 9)            0         \n",
      "_________________________________________________________________\n",
      "lstm_7 (LSTM)                (None, 150)               96000     \n",
      "_________________________________________________________________\n",
      "dropout_5 (Dropout)          (None, 150)               0         \n",
      "_________________________________________________________________\n",
      "dense_5 (Dense)              (None, 150)               22650     \n",
      "_________________________________________________________________\n",
      "lstm_out (Dense)             (None, 6)                 906       \n",
      "=================================================================\n",
      "Total params: 119,556\n",
      "Trainable params: 119,556\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n",
      "Train on 5881 samples, validate on 1471 samples\n",
      "Epoch 1/60\n",
      "5881/5881 [==============================] - 8s 1ms/step - loss: 1.7962 - acc: 0.4166 - auc: 0.6337 - recall: 0.9532 - val_loss: 1.4970 - val_acc: 0.4691 - val_auc: 0.7610 - val_recall: 0.9882\n",
      "Epoch 2/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 1.4232 - acc: 0.5253 - auc: 0.7859 - recall: 0.9923 - val_loss: 1.2394 - val_acc: 0.6200 - val_auc: 0.8127 - val_recall: 0.9945\n",
      "Epoch 3/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 2.2208 - acc: 0.5482 - auc: 0.8249 - recall: 0.9885 - val_loss: 2.2631 - val_acc: 0.6621 - val_auc: 0.8245 - val_recall: 0.9751\n",
      "Epoch 4/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 1.2140 - acc: 0.5739 - auc: 0.8293 - recall: 0.9734 - val_loss: 1.1084 - val_acc: 0.6465 - val_auc: 0.8373 - val_recall: 0.9767\n",
      "Epoch 5/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 1.0182 - acc: 0.6186 - auc: 0.8470 - recall: 0.9793 - val_loss: 1.0625 - val_acc: 0.6744 - val_auc: 0.8561 - val_recall: 0.9811\n",
      "Epoch 6/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.9303 - acc: 0.6393 - auc: 0.8627 - recall: 0.9821 - val_loss: 0.8840 - val_acc: 0.6465 - val_auc: 0.8690 - val_recall: 0.9836\n",
      "Epoch 7/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.8152 - acc: 0.6742 - auc: 0.8744 - recall: 0.9848 - val_loss: 0.9139 - val_acc: 0.6852 - val_auc: 0.8795 - val_recall: 0.9859\n",
      "Epoch 8/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.7278 - acc: 0.6997 - auc: 0.8839 - recall: 0.9866 - val_loss: 0.7409 - val_acc: 0.7199 - val_auc: 0.8881 - val_recall: 0.9874\n",
      "Epoch 9/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.6810 - acc: 0.7018 - auc: 0.8920 - recall: 0.9881 - val_loss: 0.7723 - val_acc: 0.6676 - val_auc: 0.8955 - val_recall: 0.9888\n",
      "Epoch 10/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.6717 - acc: 0.7067 - auc: 0.8985 - recall: 0.9894 - val_loss: 0.7100 - val_acc: 0.7070 - val_auc: 0.9016 - val_recall: 0.9899\n",
      "Epoch 11/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.6274 - acc: 0.7259 - auc: 0.9045 - recall: 0.9904 - val_loss: 0.6893 - val_acc: 0.7403 - val_auc: 0.9074 - val_recall: 0.9908\n",
      "Epoch 12/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.5994 - acc: 0.7400 - auc: 0.9100 - recall: 0.9912 - val_loss: 0.6791 - val_acc: 0.7281 - val_auc: 0.9125 - val_recall: 0.9916\n",
      "Epoch 13/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.6266 - acc: 0.7444 - auc: 0.9148 - recall: 0.9918 - val_loss: 0.7921 - val_acc: 0.7661 - val_auc: 0.9170 - val_recall: 0.9919\n",
      "Epoch 14/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 1.1918 - acc: 0.7478 - auc: 0.9184 - recall: 0.9914 - val_loss: 1.5687 - val_acc: 0.7240 - val_auc: 0.9187 - val_recall: 0.9896\n",
      "Epoch 15/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 1.1540 - acc: 0.6575 - auc: 0.9174 - recall: 0.9888 - val_loss: 0.7830 - val_acc: 0.7437 - val_auc: 0.9179 - val_recall: 0.9888\n",
      "Epoch 16/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.6647 - acc: 0.7592 - auc: 0.9195 - recall: 0.9890 - val_loss: 0.8238 - val_acc: 0.6934 - val_auc: 0.9210 - val_recall: 0.9891\n",
      "Epoch 17/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.5913 - acc: 0.7558 - auc: 0.9220 - recall: 0.9894 - val_loss: 0.6575 - val_acc: 0.7757 - val_auc: 0.9235 - val_recall: 0.9897\n",
      "\n",
      "Epoch 00017: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.\n",
      "Epoch 18/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.5333 - acc: 0.7876 - auc: 0.9250 - recall: 0.9900 - val_loss: 0.6492 - val_acc: 0.7886 - val_auc: 0.9265 - val_recall: 0.9902\n",
      "Epoch 19/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.5071 - acc: 0.8021 - auc: 0.9280 - recall: 0.9905 - val_loss: 0.6361 - val_acc: 0.7988 - val_auc: 0.9294 - val_recall: 0.9908\n",
      "Epoch 20/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4877 - acc: 0.8114 - auc: 0.9307 - recall: 0.9910 - val_loss: 0.6204 - val_acc: 0.8069 - val_auc: 0.9320 - val_recall: 0.9912\n",
      "Epoch 21/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4694 - acc: 0.8175 - auc: 0.9333 - recall: 0.9914 - val_loss: 0.6001 - val_acc: 0.8382 - val_auc: 0.9345 - val_recall: 0.9916\n",
      "Epoch 22/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.6255 - acc: 0.8162 - auc: 0.9357 - recall: 0.9917 - val_loss: 0.8997 - val_acc: 0.7804 - val_auc: 0.9364 - val_recall: 0.9915\n",
      "\n",
      "Epoch 00022: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.\n",
      "Epoch 23/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.7090 - acc: 0.7968 - auc: 0.9370 - recall: 0.9914 - val_loss: 0.7633 - val_acc: 0.8124 - val_auc: 0.9377 - val_recall: 0.9913\n",
      "Epoch 24/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.5287 - acc: 0.7961 - auc: 0.9384 - recall: 0.9913 - val_loss: 0.5898 - val_acc: 0.8049 - val_auc: 0.9393 - val_recall: 0.9914\n",
      "Epoch 25/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4786 - acc: 0.8249 - auc: 0.9402 - recall: 0.9916 - val_loss: 0.6181 - val_acc: 0.8396 - val_auc: 0.9411 - val_recall: 0.9917\n",
      "Epoch 26/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.5109 - acc: 0.8179 - auc: 0.9419 - recall: 0.9918 - val_loss: 0.6756 - val_acc: 0.7288 - val_auc: 0.9426 - val_recall: 0.9919\n",
      "Epoch 27/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.5129 - acc: 0.7789 - auc: 0.9430 - recall: 0.9920 - val_loss: 0.6032 - val_acc: 0.7872 - val_auc: 0.9436 - val_recall: 0.9922\n",
      "Epoch 28/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4736 - acc: 0.8067 - auc: 0.9442 - recall: 0.9923 - val_loss: 0.5967 - val_acc: 0.7940 - val_auc: 0.9449 - val_recall: 0.9925\n",
      "\n",
      "Epoch 00028: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.\n",
      "Epoch 29/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4654 - acc: 0.8126 - auc: 0.9455 - recall: 0.9926 - val_loss: 0.5923 - val_acc: 0.7974 - val_auc: 0.9461 - val_recall: 0.9927\n",
      "Epoch 30/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4506 - acc: 0.8226 - auc: 0.9467 - recall: 0.9928 - val_loss: 0.5882 - val_acc: 0.8029 - val_auc: 0.9473 - val_recall: 0.9930\n",
      "Epoch 31/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4506 - acc: 0.8279 - auc: 0.9479 - recall: 0.9931 - val_loss: 0.5847 - val_acc: 0.8056 - val_auc: 0.9484 - val_recall: 0.9932\n",
      "\n",
      "Epoch 00031: ReduceLROnPlateau reducing learning rate to 6.25000029685907e-05.\n",
      "Epoch 32/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4404 - acc: 0.8279 - auc: 0.9490 - recall: 0.9933 - val_loss: 0.5816 - val_acc: 0.8063 - val_auc: 0.9495 - val_recall: 0.9934\n",
      "Epoch 33/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4448 - acc: 0.8262 - auc: 0.9500 - recall: 0.9935 - val_loss: 0.5776 - val_acc: 0.8097 - val_auc: 0.9505 - val_recall: 0.9936\n",
      "Epoch 34/60\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4488 - acc: 0.8298 - auc: 0.9510 - recall: 0.9936 - val_loss: 0.5852 - val_acc: 0.8137 - val_auc: 0.9515 - val_recall: 0.9937\n",
      "Epoch 35/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4472 - acc: 0.8289 - auc: 0.9519 - recall: 0.9938 - val_loss: 0.5702 - val_acc: 0.8205 - val_auc: 0.9524 - val_recall: 0.9939\n",
      "Epoch 36/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4604 - acc: 0.8369 - auc: 0.9528 - recall: 0.9939 - val_loss: 0.5676 - val_acc: 0.8199 - val_auc: 0.9532 - val_recall: 0.9940\n",
      "Epoch 37/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4419 - acc: 0.8335 - auc: 0.9536 - recall: 0.9941 - val_loss: 0.5685 - val_acc: 0.8246 - val_auc: 0.9540 - val_recall: 0.9941\n",
      "\n",
      "Epoch 00037: ReduceLROnPlateau reducing learning rate to 3.125000148429535e-05.\n",
      "Epoch 38/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4410 - acc: 0.8363 - auc: 0.9543 - recall: 0.9942 - val_loss: 0.5670 - val_acc: 0.8287 - val_auc: 0.9547 - val_recall: 0.9942\n",
      "Epoch 39/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4405 - acc: 0.8320 - auc: 0.9550 - recall: 0.9943 - val_loss: 0.5650 - val_acc: 0.8300 - val_auc: 0.9554 - val_recall: 0.9944\n",
      "Epoch 40/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4366 - acc: 0.8369 - auc: 0.9557 - recall: 0.9944 - val_loss: 0.5625 - val_acc: 0.8273 - val_auc: 0.9561 - val_recall: 0.9945\n",
      "\n",
      "Epoch 00040: ReduceLROnPlateau reducing learning rate to 1.5625000742147677e-05.\n",
      "Epoch 41/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4443 - acc: 0.8402 - auc: 0.9564 - recall: 0.9945 - val_loss: 0.5727 - val_acc: 0.8294 - val_auc: 0.9567 - val_recall: 0.9946\n",
      "Epoch 42/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4330 - acc: 0.8366 - auc: 0.9570 - recall: 0.9946 - val_loss: 0.5717 - val_acc: 0.8280 - val_auc: 0.9573 - val_recall: 0.9947\n",
      "Epoch 43/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4398 - acc: 0.8357 - auc: 0.9576 - recall: 0.9947 - val_loss: 0.5710 - val_acc: 0.8307 - val_auc: 0.9579 - val_recall: 0.9948\n",
      "\n",
      "Epoch 00043: ReduceLROnPlateau reducing learning rate to 7.812500371073838e-06.\n",
      "Epoch 44/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4356 - acc: 0.8376 - auc: 0.9581 - recall: 0.9948 - val_loss: 0.5594 - val_acc: 0.8300 - val_auc: 0.9584 - val_recall: 0.9948\n",
      "Restoring model weights from the end of the best epoch\n",
      "Epoch 00044: early stopping\n",
      "training time: 293.0284957885742s\n",
      "Train on 5881 samples, validate on 1471 samples\n",
      "Epoch 1/60\n",
      "5881/5881 [==============================] - 8s 1ms/step - loss: 1.5610 - acc: 0.4011 - auc: 0.6489 - recall: 0.9569 - val_loss: 1.3276 - val_acc: 0.5418 - val_auc: 0.7702 - val_recall: 0.9988\n",
      "Epoch 2/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 1.4608 - acc: 0.5535 - auc: 0.8036 - recall: 0.9985 - val_loss: 3.2944 - val_acc: 0.4779 - val_auc: 0.8152 - val_recall: 0.9864\n",
      "Epoch 3/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 1.9089 - acc: 0.5270 - auc: 0.8110 - recall: 0.9689 - val_loss: 1.1568 - val_acc: 0.5588 - val_auc: 0.8218 - val_recall: 0.9697\n",
      "Epoch 4/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 2.0437 - acc: 0.5732 - auc: 0.8300 - recall: 0.9681 - val_loss: 0.9462 - val_acc: 0.6193 - val_auc: 0.8341 - val_recall: 0.9623\n",
      "Epoch 5/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 1.3971 - acc: 0.6094 - auc: 0.8398 - recall: 0.9642 - val_loss: 0.7673 - val_acc: 0.6818 - val_auc: 0.8485 - val_recall: 0.9651\n",
      "Epoch 6/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.8452 - acc: 0.6382 - auc: 0.8564 - recall: 0.9681 - val_loss: 0.7693 - val_acc: 0.6526 - val_auc: 0.8643 - val_recall: 0.9709\n",
      "Epoch 7/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.6706 - acc: 0.6980 - auc: 0.8716 - recall: 0.9731 - val_loss: 0.7158 - val_acc: 0.6696 - val_auc: 0.8787 - val_recall: 0.9751\n",
      "Epoch 8/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.6294 - acc: 0.7026 - auc: 0.8843 - recall: 0.9768 - val_loss: 0.7936 - val_acc: 0.6703 - val_auc: 0.8894 - val_recall: 0.9782\n",
      "Epoch 9/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.7475 - acc: 0.7208 - auc: 0.8934 - recall: 0.9793 - val_loss: 1.5014 - val_acc: 0.6587 - val_auc: 0.8968 - val_recall: 0.9797\n",
      "Epoch 10/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 1.4847 - acc: 0.6744 - auc: 0.8986 - recall: 0.9787 - val_loss: 3.5390 - val_acc: 0.5255 - val_auc: 0.8973 - val_recall: 0.9751\n",
      "Epoch 11/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 2.8043 - acc: 0.6057 - auc: 0.8924 - recall: 0.9683 - val_loss: 0.8839 - val_acc: 0.7437 - val_auc: 0.8916 - val_recall: 0.9653\n",
      "\n",
      "Epoch 00011: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.\n",
      "Epoch 12/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 1.6764 - acc: 0.6932 - auc: 0.8927 - recall: 0.9644 - val_loss: 0.7520 - val_acc: 0.7580 - val_auc: 0.8938 - val_recall: 0.9634\n",
      "Epoch 13/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 1.6147 - acc: 0.7242 - auc: 0.8950 - recall: 0.9626 - val_loss: 0.6567 - val_acc: 0.7893 - val_auc: 0.8965 - val_recall: 0.9620\n",
      "Epoch 14/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 1.3336 - acc: 0.7504 - auc: 0.8983 - recall: 0.9616 - val_loss: 0.6675 - val_acc: 0.7335 - val_auc: 0.9001 - val_recall: 0.9616\n",
      "Epoch 15/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 1.0385 - acc: 0.7759 - auc: 0.9022 - recall: 0.9620 - val_loss: 0.6100 - val_acc: 0.8144 - val_auc: 0.9042 - val_recall: 0.9622\n",
      "Epoch 16/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.9460 - acc: 0.8152 - auc: 0.9064 - recall: 0.9626 - val_loss: 0.5551 - val_acc: 0.8103 - val_auc: 0.9085 - val_recall: 0.9629\n",
      "Epoch 17/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.6877 - acc: 0.8385 - auc: 0.9108 - recall: 0.9633 - val_loss: 0.5200 - val_acc: 0.8049 - val_auc: 0.9132 - val_recall: 0.9640\n",
      "Epoch 18/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4320 - acc: 0.8522 - auc: 0.9157 - recall: 0.9649 - val_loss: 0.5805 - val_acc: 0.7675 - val_auc: 0.9179 - val_recall: 0.9658\n",
      "Epoch 19/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4541 - acc: 0.8111 - auc: 0.9198 - recall: 0.9666 - val_loss: 0.5543 - val_acc: 0.8504 - val_auc: 0.9215 - val_recall: 0.9675\n",
      "Epoch 20/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 1.7668 - acc: 0.7492 - auc: 0.9225 - recall: 0.9675 - val_loss: 2.0309 - val_acc: 0.7165 - val_auc: 0.9212 - val_recall: 0.9652\n",
      "\n",
      "Epoch 00020: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.\n",
      "Epoch 21/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.6904 - acc: 0.8448 - auc: 0.9222 - recall: 0.9650 - val_loss: 0.4715 - val_acc: 0.8273 - val_auc: 0.9238 - val_recall: 0.9656\n",
      "Epoch 22/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.4443 - acc: 0.8687 - auc: 0.9255 - recall: 0.9663 - val_loss: 0.4706 - val_acc: 0.8307 - val_auc: 0.9271 - val_recall: 0.9669\n",
      "Epoch 23/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.5895 - acc: 0.8283 - auc: 0.9286 - recall: 0.9675 - val_loss: 1.0194 - val_acc: 0.7791 - val_auc: 0.9295 - val_recall: 0.9678\n",
      "Epoch 24/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.5413 - acc: 0.8473 - auc: 0.9303 - recall: 0.9680 - val_loss: 0.4797 - val_acc: 0.8307 - val_auc: 0.9316 - val_recall: 0.9686\n",
      "\n",
      "Epoch 00024: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.\n",
      "Epoch 25/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.4309 - acc: 0.8726 - auc: 0.9329 - recall: 0.9691 - val_loss: 0.4725 - val_acc: 0.8409 - val_auc: 0.9341 - val_recall: 0.9696\n",
      "Epoch 26/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.4417 - acc: 0.8766 - auc: 0.9353 - recall: 0.9700 - val_loss: 0.4655 - val_acc: 0.8484 - val_auc: 0.9364 - val_recall: 0.9704\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 27/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.3937 - acc: 0.8815 - auc: 0.9375 - recall: 0.9709 - val_loss: 0.4696 - val_acc: 0.8464 - val_auc: 0.9386 - val_recall: 0.9713\n",
      "Epoch 28/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.3710 - acc: 0.8796 - auc: 0.9396 - recall: 0.9718 - val_loss: 0.4686 - val_acc: 0.8511 - val_auc: 0.9406 - val_recall: 0.9722\n",
      "\n",
      "Epoch 00028: ReduceLROnPlateau reducing learning rate to 6.25000029685907e-05.\n",
      "Epoch 29/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.3675 - acc: 0.8832 - auc: 0.9416 - recall: 0.9726 - val_loss: 0.4698 - val_acc: 0.8443 - val_auc: 0.9425 - val_recall: 0.9730\n",
      "Epoch 30/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.3985 - acc: 0.8789 - auc: 0.9433 - recall: 0.9733 - val_loss: 0.4692 - val_acc: 0.8504 - val_auc: 0.9442 - val_recall: 0.9737\n",
      "Epoch 31/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.3900 - acc: 0.8806 - auc: 0.9450 - recall: 0.9740 - val_loss: 0.4654 - val_acc: 0.8552 - val_auc: 0.9457 - val_recall: 0.9743\n",
      "Epoch 32/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.4200 - acc: 0.8725 - auc: 0.9465 - recall: 0.9746 - val_loss: 0.4994 - val_acc: 0.8076 - val_auc: 0.9471 - val_recall: 0.9749\n",
      "Epoch 33/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.4005 - acc: 0.8556 - auc: 0.9478 - recall: 0.9752 - val_loss: 0.4882 - val_acc: 0.8144 - val_auc: 0.9484 - val_recall: 0.9756\n",
      "\n",
      "Epoch 00033: ReduceLROnPlateau reducing learning rate to 3.125000148429535e-05.\n",
      "Epoch 34/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.3629 - acc: 0.8561 - auc: 0.9490 - recall: 0.9759 - val_loss: 0.4873 - val_acc: 0.8205 - val_auc: 0.9496 - val_recall: 0.9762\n",
      "Epoch 35/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.3512 - acc: 0.8670 - auc: 0.9502 - recall: 0.9765 - val_loss: 0.4842 - val_acc: 0.8280 - val_auc: 0.9508 - val_recall: 0.9768\n",
      "Epoch 36/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.4096 - acc: 0.8628 - auc: 0.9513 - recall: 0.9771 - val_loss: 0.4807 - val_acc: 0.8348 - val_auc: 0.9518 - val_recall: 0.9773\n",
      "\n",
      "Epoch 00036: ReduceLROnPlateau reducing learning rate to 1.5625000742147677e-05.\n",
      "Epoch 37/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.3622 - acc: 0.8706 - auc: 0.9523 - recall: 0.9776 - val_loss: 0.4794 - val_acc: 0.8375 - val_auc: 0.9528 - val_recall: 0.9778\n",
      "Epoch 38/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.3449 - acc: 0.8745 - auc: 0.9533 - recall: 0.9781 - val_loss: 0.4786 - val_acc: 0.8430 - val_auc: 0.9538 - val_recall: 0.9784\n",
      "Epoch 39/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.3831 - acc: 0.8698 - auc: 0.9543 - recall: 0.9786 - val_loss: 0.4779 - val_acc: 0.8450 - val_auc: 0.9547 - val_recall: 0.9788\n",
      "Epoch 40/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.3494 - acc: 0.8721 - auc: 0.9552 - recall: 0.9790 - val_loss: 0.4776 - val_acc: 0.8477 - val_auc: 0.9556 - val_recall: 0.9793\n",
      "Epoch 41/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.3606 - acc: 0.8740 - auc: 0.9560 - recall: 0.9795 - val_loss: 0.4771 - val_acc: 0.8484 - val_auc: 0.9564 - val_recall: 0.9797\n",
      "Epoch 42/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.3585 - acc: 0.8733 - auc: 0.9568 - recall: 0.9799 - val_loss: 0.4767 - val_acc: 0.8498 - val_auc: 0.9572 - val_recall: 0.9801\n",
      "\n",
      "Epoch 00042: ReduceLROnPlateau reducing learning rate to 7.812500371073838e-06.\n",
      "Epoch 43/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.3773 - acc: 0.8786 - auc: 0.9576 - recall: 0.9803 - val_loss: 0.4766 - val_acc: 0.8511 - val_auc: 0.9579 - val_recall: 0.9805\n",
      "Epoch 44/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.3455 - acc: 0.8755 - auc: 0.9583 - recall: 0.9807 - val_loss: 0.4765 - val_acc: 0.8511 - val_auc: 0.9587 - val_recall: 0.9808\n",
      "Epoch 45/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.3608 - acc: 0.8750 - auc: 0.9590 - recall: 0.9810 - val_loss: 0.4764 - val_acc: 0.8511 - val_auc: 0.9593 - val_recall: 0.9812\n",
      "\n",
      "Epoch 00045: ReduceLROnPlateau reducing learning rate to 3.906250185536919e-06.\n",
      "Epoch 46/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.3779 - acc: 0.8738 - auc: 0.9596 - recall: 0.9813 - val_loss: 0.4763 - val_acc: 0.8511 - val_auc: 0.9599 - val_recall: 0.9815\n",
      "Epoch 47/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.3524 - acc: 0.8764 - auc: 0.9603 - recall: 0.9817 - val_loss: 0.4762 - val_acc: 0.8511 - val_auc: 0.9606 - val_recall: 0.9818\n",
      "Epoch 48/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.3494 - acc: 0.8767 - auc: 0.9609 - recall: 0.9820 - val_loss: 0.4761 - val_acc: 0.8511 - val_auc: 0.9612 - val_recall: 0.9821\n",
      "\n",
      "Epoch 00048: ReduceLROnPlateau reducing learning rate to 1.9531250927684596e-06.\n",
      "Epoch 49/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.3764 - acc: 0.8733 - auc: 0.9614 - recall: 0.9823 - val_loss: 0.4761 - val_acc: 0.8511 - val_auc: 0.9617 - val_recall: 0.9824\n",
      "Restoring model weights from the end of the best epoch\n",
      "Epoch 00049: early stopping\n",
      "training time: 329.1411781311035s\n",
      "Train on 5881 samples, validate on 1471 samples\n",
      "Epoch 1/60\n",
      "5881/5881 [==============================] - 8s 1ms/step - loss: 1.7984 - acc: 0.4299 - auc: 0.6958 - recall: 0.9507 - val_loss: 1.3126 - val_acc: 0.4772 - val_auc: 0.7922 - val_recall: 0.9844\n",
      "Epoch 2/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 1.4176 - acc: 0.5586 - auc: 0.8169 - recall: 0.9887 - val_loss: 2.1104 - val_acc: 0.4541 - val_auc: 0.8318 - val_recall: 0.9826\n",
      "Epoch 3/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 1.0927 - acc: 0.6115 - auc: 0.8421 - recall: 0.9801 - val_loss: 0.9118 - val_acc: 0.6710 - val_auc: 0.8572 - val_recall: 0.9828\n",
      "Epoch 4/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.8627 - acc: 0.6575 - auc: 0.8683 - recall: 0.9850 - val_loss: 0.8165 - val_acc: 0.6628 - val_auc: 0.8783 - val_recall: 0.9867\n",
      "Epoch 5/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.7195 - acc: 0.7023 - auc: 0.8864 - recall: 0.9882 - val_loss: 0.7455 - val_acc: 0.7097 - val_auc: 0.8939 - val_recall: 0.9894\n",
      "Epoch 6/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.6326 - acc: 0.7191 - auc: 0.8997 - recall: 0.9903 - val_loss: 0.7147 - val_acc: 0.7192 - val_auc: 0.9055 - val_recall: 0.9911\n",
      "Epoch 7/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.5621 - acc: 0.7584 - auc: 0.9103 - recall: 0.9918 - val_loss: 0.7455 - val_acc: 0.7593 - val_auc: 0.9151 - val_recall: 0.9924\n",
      "Epoch 8/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.5825 - acc: 0.7801 - auc: 0.9189 - recall: 0.9926 - val_loss: 0.6747 - val_acc: 0.7593 - val_auc: 0.9224 - val_recall: 0.9929\n",
      "Epoch 9/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.5013 - acc: 0.7944 - auc: 0.9256 - recall: 0.9933 - val_loss: 0.7014 - val_acc: 0.7315 - val_auc: 0.9288 - val_recall: 0.9937\n",
      "Epoch 10/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.5189 - acc: 0.8215 - auc: 0.9313 - recall: 0.9936 - val_loss: 0.6239 - val_acc: 0.8287 - val_auc: 0.9343 - val_recall: 0.9939\n",
      "Epoch 11/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 1.0119 - acc: 0.8204 - auc: 0.9366 - recall: 0.9936 - val_loss: 2.8343 - val_acc: 0.7043 - val_auc: 0.9363 - val_recall: 0.9905\n",
      "Epoch 12/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 1.0872 - acc: 0.7834 - auc: 0.9348 - recall: 0.9871 - val_loss: 0.5901 - val_acc: 0.7593 - val_auc: 0.9362 - val_recall: 0.9871\n",
      "Epoch 13/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4103 - acc: 0.8504 - auc: 0.9383 - recall: 0.9875 - val_loss: 0.6069 - val_acc: 0.8328 - val_auc: 0.9403 - val_recall: 0.9879\n",
      "\n",
      "Epoch 00013: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.\n",
      "Epoch 14/60\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5881/5881 [==============================] - 6s 1ms/step - loss: 1.3587 - acc: 0.7988 - auc: 0.9413 - recall: 0.9872 - val_loss: 1.9574 - val_acc: 0.7553 - val_auc: 0.9402 - val_recall: 0.9844\n",
      "Epoch 15/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.7421 - acc: 0.8522 - auc: 0.9409 - recall: 0.9835 - val_loss: 0.7738 - val_acc: 0.7831 - val_auc: 0.9420 - val_recall: 0.9835\n",
      "Epoch 16/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.3771 - acc: 0.8704 - auc: 0.9432 - recall: 0.9840 - val_loss: 0.5116 - val_acc: 0.8552 - val_auc: 0.9449 - val_recall: 0.9845\n",
      "Epoch 17/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.2796 - acc: 0.8961 - auc: 0.9465 - recall: 0.9850 - val_loss: 0.5321 - val_acc: 0.8742 - val_auc: 0.9481 - val_recall: 0.9854\n",
      "Epoch 18/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.2549 - acc: 0.9058 - auc: 0.9496 - recall: 0.9858 - val_loss: 0.5929 - val_acc: 0.8865 - val_auc: 0.9510 - val_recall: 0.9862\n",
      "Epoch 19/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.2462 - acc: 0.9180 - auc: 0.9523 - recall: 0.9865 - val_loss: 0.5429 - val_acc: 0.8980 - val_auc: 0.9536 - val_recall: 0.9868\n",
      "\n",
      "Epoch 00019: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.\n",
      "Epoch 20/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.5142 - acc: 0.9138 - auc: 0.9546 - recall: 0.9868 - val_loss: 0.6966 - val_acc: 0.8994 - val_auc: 0.9555 - val_recall: 0.9866\n",
      "Epoch 21/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.6473 - acc: 0.9078 - auc: 0.9561 - recall: 0.9863 - val_loss: 0.7579 - val_acc: 0.8919 - val_auc: 0.9567 - val_recall: 0.9859\n",
      "Epoch 22/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4823 - acc: 0.9213 - auc: 0.9575 - recall: 0.9858 - val_loss: 0.6803 - val_acc: 0.8946 - val_auc: 0.9582 - val_recall: 0.9857\n",
      "Epoch 23/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.9298 - acc: 0.8944 - auc: 0.9587 - recall: 0.9854 - val_loss: 1.1070 - val_acc: 0.8770 - val_auc: 0.9586 - val_recall: 0.9845\n",
      "\n",
      "Epoch 00023: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.\n",
      "Epoch 24/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 1.0631 - acc: 0.8912 - auc: 0.9587 - recall: 0.9838 - val_loss: 1.1129 - val_acc: 0.8804 - val_auc: 0.9586 - val_recall: 0.9830\n",
      "Epoch 25/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 1.0848 - acc: 0.8891 - auc: 0.9587 - recall: 0.9823 - val_loss: 0.9731 - val_acc: 0.8844 - val_auc: 0.9586 - val_recall: 0.9816\n",
      "Epoch 26/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 1.1612 - acc: 0.8876 - auc: 0.9587 - recall: 0.9810 - val_loss: 1.2995 - val_acc: 0.8668 - val_auc: 0.9585 - val_recall: 0.9801\n",
      "\n",
      "Epoch 00026: ReduceLROnPlateau reducing learning rate to 6.25000029685907e-05.\n",
      "Epoch 27/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 1.1815 - acc: 0.8862 - auc: 0.9583 - recall: 0.9793 - val_loss: 1.2142 - val_acc: 0.8763 - val_auc: 0.9582 - val_recall: 0.9786\n",
      "Epoch 28/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 1.2059 - acc: 0.8861 - auc: 0.9581 - recall: 0.9779 - val_loss: 1.1299 - val_acc: 0.8722 - val_auc: 0.9580 - val_recall: 0.9772\n",
      "Epoch 29/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 1.2642 - acc: 0.8803 - auc: 0.9580 - recall: 0.9766 - val_loss: 1.2017 - val_acc: 0.8688 - val_auc: 0.9578 - val_recall: 0.9758\n",
      "\n",
      "Epoch 00029: ReduceLROnPlateau reducing learning rate to 3.125000148429535e-05.\n",
      "Epoch 30/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 1.2180 - acc: 0.8847 - auc: 0.9577 - recall: 0.9751 - val_loss: 1.0335 - val_acc: 0.8770 - val_auc: 0.9576 - val_recall: 0.9745\n",
      "Restoring model weights from the end of the best epoch\n",
      "Epoch 00030: early stopping\n",
      "training time: 204.52269887924194s\n",
      "__________________________________________________________________________________________________\n",
      "Layer (type)                    Output Shape         Param #     Connected to                     \n",
      "==================================================================================================\n",
      "input_8 (InputLayer)            (None, 128, 9)       0                                            \n",
      "__________________________________________________________________________________________________\n",
      "lambda_1 (Lambda)               [(None, 128), (None, 0           input_8[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "dense_8 (Dense)                 (None, 30)           3870        lambda_1[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_9 (Dense)                 (None, 30)           3870        lambda_1[0][1]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_10 (Dense)                (None, 30)           3870        lambda_1[0][2]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_11 (Dense)                (None, 30)           3870        lambda_1[0][3]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_12 (Dense)                (None, 30)           3870        lambda_1[0][4]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_13 (Dense)                (None, 30)           3870        lambda_1[0][5]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_14 (Dense)                (None, 30)           3870        lambda_1[0][6]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_15 (Dense)                (None, 30)           3870        lambda_1[0][7]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_16 (Dense)                (None, 30)           3870        lambda_1[0][8]                   \n",
      "__________________________________________________________________________________________________\n",
      "lambda_2 (Lambda)               (None, 30, 9)        0           dense_8[0][0]                    \n",
      "                                                                 dense_9[0][0]                    \n",
      "                                                                 dense_10[0][0]                   \n",
      "                                                                 dense_11[0][0]                   \n",
      "                                                                 dense_12[0][0]                   \n",
      "                                                                 dense_13[0][0]                   \n",
      "                                                                 dense_14[0][0]                   \n",
      "                                                                 dense_15[0][0]                   \n",
      "                                                                 dense_16[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "dropout_8 (Dropout)             (None, 30, 9)        0           lambda_2[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "flatten_1 (Flatten)             (None, 270)          0           dropout_8[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "dense_17 (Dense)                (None, 300)          81300       flatten_1[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "dropout_9 (Dropout)             (None, 300)          0           dense_17[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_18 (Dense)                (None, 300)          90300       dropout_9[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "dense_19 (Dense)                (None, 20)           6020        dense_18[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_2_out (Dense)             (None, 6)            126         dense_19[0][0]                   \n",
      "==================================================================================================\n",
      "Total params: 212,576\n",
      "Trainable params: 212,576\n",
      "Non-trainable params: 0\n",
      "__________________________________________________________________________________________________\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train on 5881 samples, validate on 1471 samples\n",
      "Epoch 1/60\n",
      "5881/5881 [==============================] - 1s 230us/step - loss: 1.0672 - acc: 0.5707 - auc: 0.7505 - recall: 0.9575 - val_loss: 0.5765 - val_acc: 0.7825 - val_auc: 0.9027 - val_recall: 1.0000\n",
      "Epoch 2/60\n",
      "5881/5881 [==============================] - 0s 57us/step - loss: 0.4546 - acc: 0.8140 - auc: 0.9310 - recall: 1.0000 - val_loss: 0.4610 - val_acc: 0.8443 - val_auc: 0.9482 - val_recall: 1.0000\n",
      "Epoch 3/60\n",
      "5881/5881 [==============================] - 0s 53us/step - loss: 0.3040 - acc: 0.8876 - auc: 0.9581 - recall: 1.0000 - val_loss: 0.4041 - val_acc: 0.8668 - val_auc: 0.9654 - val_recall: 1.0000\n",
      "Epoch 4/60\n",
      "5881/5881 [==============================] - 0s 52us/step - loss: 0.2421 - acc: 0.9097 - auc: 0.9701 - recall: 1.0000 - val_loss: 0.3532 - val_acc: 0.8933 - val_auc: 0.9739 - val_recall: 1.0000\n",
      "Epoch 5/60\n",
      "5881/5881 [==============================] - 0s 51us/step - loss: 0.1989 - acc: 0.9218 - auc: 0.9767 - recall: 1.0000 - val_loss: 0.3333 - val_acc: 0.9123 - val_auc: 0.9790 - val_recall: 1.0000\n",
      "Epoch 6/60\n",
      "5881/5881 [==============================] - 0s 53us/step - loss: 0.1577 - acc: 0.9398 - auc: 0.9809 - recall: 1.0000 - val_loss: 0.3049 - val_acc: 0.9143 - val_auc: 0.9826 - val_recall: 1.0000\n",
      "Epoch 7/60\n",
      "5881/5881 [==============================] - 0s 53us/step - loss: 0.1403 - acc: 0.9446 - auc: 0.9839 - recall: 1.0000 - val_loss: 0.3189 - val_acc: 0.9116 - val_auc: 0.9850 - val_recall: 1.0000\n",
      "Epoch 8/60\n",
      "5881/5881 [==============================] - 0s 53us/step - loss: 0.1224 - acc: 0.9503 - auc: 0.9859 - recall: 1.0000 - val_loss: 0.2760 - val_acc: 0.9245 - val_auc: 0.9868 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00008: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.\n",
      "Epoch 9/60\n",
      "5881/5881 [==============================] - 0s 56us/step - loss: 0.1092 - acc: 0.9553 - auc: 0.9876 - recall: 1.0000 - val_loss: 0.2887 - val_acc: 0.9245 - val_auc: 0.9882 - val_recall: 1.0000\n",
      "Epoch 10/60\n",
      "5881/5881 [==============================] - 0s 56us/step - loss: 0.1018 - acc: 0.9570 - auc: 0.9888 - recall: 1.0000 - val_loss: 0.2993 - val_acc: 0.9266 - val_auc: 0.9893 - val_recall: 1.0000\n",
      "Epoch 11/60\n",
      "5881/5881 [==============================] - 0s 55us/step - loss: 0.0953 - acc: 0.9623 - auc: 0.9897 - recall: 1.0000 - val_loss: 0.2960 - val_acc: 0.9279 - val_auc: 0.9901 - val_recall: 1.0000\n",
      "Epoch 12/60\n",
      "5881/5881 [==============================] - 0s 54us/step - loss: 0.0934 - acc: 0.9606 - auc: 0.9904 - recall: 1.0000 - val_loss: 0.2924 - val_acc: 0.9279 - val_auc: 0.9907 - val_recall: 1.0000\n",
      "Epoch 13/60\n",
      "5881/5881 [==============================] - 0s 53us/step - loss: 0.0891 - acc: 0.9611 - auc: 0.9910 - recall: 1.0000 - val_loss: 0.2995 - val_acc: 0.9279 - val_auc: 0.9912 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00013: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.\n",
      "Epoch 14/60\n",
      "5881/5881 [==============================] - 0s 53us/step - loss: 0.0845 - acc: 0.9640 - auc: 0.9915 - recall: 1.0000 - val_loss: 0.2962 - val_acc: 0.9279 - val_auc: 0.9916 - val_recall: 1.0000\n",
      "Epoch 15/60\n",
      "5881/5881 [==============================] - 0s 54us/step - loss: 0.0833 - acc: 0.9634 - auc: 0.9918 - recall: 1.0000 - val_loss: 0.2975 - val_acc: 0.9300 - val_auc: 0.9920 - val_recall: 1.0000\n",
      "Epoch 16/60\n",
      "5881/5881 [==============================] - 0s 54us/step - loss: 0.0834 - acc: 0.9645 - auc: 0.9922 - recall: 1.0000 - val_loss: 0.3008 - val_acc: 0.9313 - val_auc: 0.9923 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00016: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.\n",
      "Epoch 17/60\n",
      "5881/5881 [==============================] - 0s 53us/step - loss: 0.0797 - acc: 0.9653 - auc: 0.9925 - recall: 1.0000 - val_loss: 0.3085 - val_acc: 0.9279 - val_auc: 0.9926 - val_recall: 1.0000\n",
      "Epoch 18/60\n",
      "5881/5881 [==============================] - 0s 54us/step - loss: 0.0824 - acc: 0.9645 - auc: 0.9927 - recall: 1.0000 - val_loss: 0.3059 - val_acc: 0.9286 - val_auc: 0.9928 - val_recall: 1.0000\n",
      "Epoch 19/60\n",
      "5881/5881 [==============================] - 0s 54us/step - loss: 0.0798 - acc: 0.9651 - auc: 0.9929 - recall: 1.0000 - val_loss: 0.3072 - val_acc: 0.9300 - val_auc: 0.9930 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00019: ReduceLROnPlateau reducing learning rate to 6.25000029685907e-05.\n",
      "Epoch 20/60\n",
      "5881/5881 [==============================] - 0s 54us/step - loss: 0.0785 - acc: 0.9663 - auc: 0.9931 - recall: 1.0000 - val_loss: 0.3056 - val_acc: 0.9293 - val_auc: 0.9932 - val_recall: 1.0000\n",
      "Restoring model weights from the end of the best epoch\n",
      "Epoch 00020: early stopping\n",
      "training time: 17.986271381378174s\n",
      "Train on 5881 samples, validate on 1471 samples\n",
      "Epoch 1/60\n",
      "5881/5881 [==============================] - 1s 238us/step - loss: 1.0522 - acc: 0.5630 - auc: 0.7559 - recall: 0.9575 - val_loss: 0.6562 - val_acc: 0.7913 - val_auc: 0.8957 - val_recall: 1.0000\n",
      "Epoch 2/60\n",
      "5881/5881 [==============================] - 0s 56us/step - loss: 0.4436 - acc: 0.8218 - auc: 0.9268 - recall: 1.0000 - val_loss: 0.4560 - val_acc: 0.8566 - val_auc: 0.9472 - val_recall: 1.0000\n",
      "Epoch 3/60\n",
      "5881/5881 [==============================] - 0s 56us/step - loss: 0.2858 - acc: 0.8934 - auc: 0.9574 - recall: 1.0000 - val_loss: 0.3935 - val_acc: 0.8770 - val_auc: 0.9655 - val_recall: 1.0000\n",
      "Epoch 4/60\n",
      "5881/5881 [==============================] - 0s 56us/step - loss: 0.2256 - acc: 0.9128 - auc: 0.9703 - recall: 1.0000 - val_loss: 0.3299 - val_acc: 0.9069 - val_auc: 0.9744 - val_recall: 1.0000\n",
      "Epoch 5/60\n",
      "5881/5881 [==============================] - 0s 55us/step - loss: 0.1789 - acc: 0.9335 - auc: 0.9773 - recall: 1.0000 - val_loss: 0.3061 - val_acc: 0.9171 - val_auc: 0.9798 - val_recall: 1.0000\n",
      "Epoch 6/60\n",
      "5881/5881 [==============================] - 0s 56us/step - loss: 0.1508 - acc: 0.9424 - auc: 0.9817 - recall: 1.0000 - val_loss: 0.3197 - val_acc: 0.9239 - val_auc: 0.9832 - val_recall: 1.0000\n",
      "Epoch 7/60\n",
      "5881/5881 [==============================] - 0s 56us/step - loss: 0.1414 - acc: 0.9442 - auc: 0.9844 - recall: 1.0000 - val_loss: 0.3144 - val_acc: 0.9259 - val_auc: 0.9854 - val_recall: 1.0000\n",
      "Epoch 8/60\n",
      "5881/5881 [==============================] - 0s 56us/step - loss: 0.1240 - acc: 0.9478 - auc: 0.9863 - recall: 1.0000 - val_loss: 0.3117 - val_acc: 0.9239 - val_auc: 0.9871 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00008: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.\n",
      "Epoch 9/60\n",
      "5881/5881 [==============================] - 0s 56us/step - loss: 0.1066 - acc: 0.9578 - auc: 0.9878 - recall: 1.0000 - val_loss: 0.3022 - val_acc: 0.9232 - val_auc: 0.9884 - val_recall: 1.0000\n",
      "Epoch 10/60\n",
      "5881/5881 [==============================] - 0s 56us/step - loss: 0.0978 - acc: 0.9599 - auc: 0.9889 - recall: 1.0000 - val_loss: 0.3067 - val_acc: 0.9259 - val_auc: 0.9894 - val_recall: 1.0000\n",
      "Epoch 11/60\n",
      "5881/5881 [==============================] - 0s 56us/step - loss: 0.0909 - acc: 0.9623 - auc: 0.9898 - recall: 1.0000 - val_loss: 0.3180 - val_acc: 0.9245 - val_auc: 0.9902 - val_recall: 1.0000\n",
      "Epoch 12/60\n",
      "5881/5881 [==============================] - 0s 55us/step - loss: 0.0890 - acc: 0.9643 - auc: 0.9905 - recall: 1.0000 - val_loss: 0.3108 - val_acc: 0.9273 - val_auc: 0.9908 - val_recall: 1.0000\n",
      "Epoch 13/60\n",
      "5881/5881 [==============================] - 0s 56us/step - loss: 0.0884 - acc: 0.9640 - auc: 0.9911 - recall: 1.0000 - val_loss: 0.3271 - val_acc: 0.9225 - val_auc: 0.9913 - val_recall: 1.0000\n",
      "Epoch 14/60\n",
      "5881/5881 [==============================] - 0s 56us/step - loss: 0.0828 - acc: 0.9646 - auc: 0.9915 - recall: 1.0000 - val_loss: 0.3149 - val_acc: 0.9245 - val_auc: 0.9917 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00014: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.\n",
      "Epoch 15/60\n",
      "5881/5881 [==============================] - 0s 56us/step - loss: 0.0825 - acc: 0.9640 - auc: 0.9919 - recall: 1.0000 - val_loss: 0.3144 - val_acc: 0.9252 - val_auc: 0.9921 - val_recall: 1.0000\n",
      "Epoch 16/60\n",
      "5881/5881 [==============================] - 0s 56us/step - loss: 0.0787 - acc: 0.9660 - auc: 0.9922 - recall: 1.0000 - val_loss: 0.3281 - val_acc: 0.9279 - val_auc: 0.9924 - val_recall: 1.0000\n",
      "Epoch 17/60\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5881/5881 [==============================] - 0s 56us/step - loss: 0.0807 - acc: 0.9641 - auc: 0.9925 - recall: 1.0000 - val_loss: 0.3174 - val_acc: 0.9252 - val_auc: 0.9927 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00017: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.\n",
      "Epoch 18/60\n",
      "5881/5881 [==============================] - 0s 57us/step - loss: 0.0763 - acc: 0.9655 - auc: 0.9928 - recall: 1.0000 - val_loss: 0.3266 - val_acc: 0.9273 - val_auc: 0.9929 - val_recall: 1.0000\n",
      "Epoch 19/60\n",
      "5881/5881 [==============================] - 0s 56us/step - loss: 0.0774 - acc: 0.9650 - auc: 0.9930 - recall: 1.0000 - val_loss: 0.3251 - val_acc: 0.9259 - val_auc: 0.9931 - val_recall: 1.0000\n",
      "Epoch 20/60\n",
      "5881/5881 [==============================] - 0s 55us/step - loss: 0.0774 - acc: 0.9677 - auc: 0.9932 - recall: 1.0000 - val_loss: 0.3271 - val_acc: 0.9259 - val_auc: 0.9932 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00020: ReduceLROnPlateau reducing learning rate to 6.25000029685907e-05.\n",
      "Epoch 21/60\n",
      "5881/5881 [==============================] - 0s 56us/step - loss: 0.0763 - acc: 0.9650 - auc: 0.9933 - recall: 1.0000 - val_loss: 0.3311 - val_acc: 0.9273 - val_auc: 0.9934 - val_recall: 1.0000\n",
      "Restoring model weights from the end of the best epoch\n",
      "Epoch 00021: early stopping\n",
      "training time: 19.37779450416565s\n",
      "Train on 5881 samples, validate on 1471 samples\n",
      "Epoch 1/60\n",
      "5881/5881 [==============================] - 1s 247us/step - loss: 0.9489 - acc: 0.6336 - auc: 0.7914 - recall: 0.9575 - val_loss: 0.5720 - val_acc: 0.8042 - val_auc: 0.9219 - val_recall: 1.0000\n",
      "Epoch 2/60\n",
      "5881/5881 [==============================] - 0s 55us/step - loss: 0.4254 - acc: 0.8262 - auc: 0.9431 - recall: 1.0000 - val_loss: 0.4623 - val_acc: 0.8552 - val_auc: 0.9562 - val_recall: 1.0000\n",
      "Epoch 3/60\n",
      "5881/5881 [==============================] - 0s 55us/step - loss: 0.2997 - acc: 0.8800 - auc: 0.9636 - recall: 1.0000 - val_loss: 0.3675 - val_acc: 0.8824 - val_auc: 0.9695 - val_recall: 1.0000\n",
      "Epoch 4/60\n",
      "5881/5881 [==============================] - 0s 55us/step - loss: 0.2335 - acc: 0.9097 - auc: 0.9735 - recall: 1.0000 - val_loss: 0.3464 - val_acc: 0.8960 - val_auc: 0.9767 - val_recall: 1.0000\n",
      "Epoch 5/60\n",
      "5881/5881 [==============================] - 0s 55us/step - loss: 0.1815 - acc: 0.9279 - auc: 0.9791 - recall: 1.0000 - val_loss: 0.3318 - val_acc: 0.9062 - val_auc: 0.9813 - val_recall: 1.0000\n",
      "Epoch 6/60\n",
      "5881/5881 [==============================] - 0s 55us/step - loss: 0.1488 - acc: 0.9403 - auc: 0.9829 - recall: 1.0000 - val_loss: 0.3051 - val_acc: 0.9137 - val_auc: 0.9843 - val_recall: 1.0000\n",
      "Epoch 7/60\n",
      "5881/5881 [==============================] - 0s 55us/step - loss: 0.1286 - acc: 0.9498 - auc: 0.9855 - recall: 1.0000 - val_loss: 0.3184 - val_acc: 0.9055 - val_auc: 0.9865 - val_recall: 1.0000\n",
      "Epoch 8/60\n",
      "5881/5881 [==============================] - 0s 56us/step - loss: 0.1156 - acc: 0.9537 - auc: 0.9873 - recall: 1.0000 - val_loss: 0.3222 - val_acc: 0.9150 - val_auc: 0.9880 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00008: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.\n",
      "Epoch 9/60\n",
      "5881/5881 [==============================] - 0s 57us/step - loss: 0.1043 - acc: 0.9566 - auc: 0.9886 - recall: 1.0000 - val_loss: 0.3196 - val_acc: 0.9198 - val_auc: 0.9891 - val_recall: 1.0000\n",
      "Epoch 10/60\n",
      "5881/5881 [==============================] - 0s 56us/step - loss: 0.0955 - acc: 0.9612 - auc: 0.9896 - recall: 1.0000 - val_loss: 0.3158 - val_acc: 0.9218 - val_auc: 0.9900 - val_recall: 1.0000\n",
      "Epoch 11/60\n",
      "5881/5881 [==============================] - 0s 56us/step - loss: 0.0937 - acc: 0.9600 - auc: 0.9904 - recall: 1.0000 - val_loss: 0.3164 - val_acc: 0.9177 - val_auc: 0.9907 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00011: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.\n",
      "Epoch 12/60\n",
      "5881/5881 [==============================] - 0s 56us/step - loss: 0.0905 - acc: 0.9621 - auc: 0.9910 - recall: 1.0000 - val_loss: 0.3121 - val_acc: 0.9191 - val_auc: 0.9912 - val_recall: 1.0000\n",
      "Epoch 13/60\n",
      "5881/5881 [==============================] - 0s 57us/step - loss: 0.0885 - acc: 0.9619 - auc: 0.9915 - recall: 1.0000 - val_loss: 0.3248 - val_acc: 0.9205 - val_auc: 0.9917 - val_recall: 1.0000\n",
      "Epoch 14/60\n",
      "5881/5881 [==============================] - 0s 57us/step - loss: 0.0859 - acc: 0.9628 - auc: 0.9918 - recall: 1.0000 - val_loss: 0.3185 - val_acc: 0.9232 - val_auc: 0.9920 - val_recall: 1.0000\n",
      "Epoch 15/60\n",
      "5881/5881 [==============================] - 0s 57us/step - loss: 0.0822 - acc: 0.9638 - auc: 0.9922 - recall: 1.0000 - val_loss: 0.3251 - val_acc: 0.9252 - val_auc: 0.9923 - val_recall: 1.0000\n",
      "Epoch 16/60\n",
      "5881/5881 [==============================] - 0s 58us/step - loss: 0.0827 - acc: 0.9640 - auc: 0.9925 - recall: 1.0000 - val_loss: 0.3232 - val_acc: 0.9259 - val_auc: 0.9926 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00016: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.\n",
      "Epoch 17/60\n",
      "5881/5881 [==============================] - 0s 57us/step - loss: 0.0797 - acc: 0.9658 - auc: 0.9927 - recall: 1.0000 - val_loss: 0.3200 - val_acc: 0.9259 - val_auc: 0.9929 - val_recall: 1.0000\n",
      "Epoch 18/60\n",
      "5881/5881 [==============================] - 0s 57us/step - loss: 0.0799 - acc: 0.9631 - auc: 0.9930 - recall: 1.0000 - val_loss: 0.3231 - val_acc: 0.9245 - val_auc: 0.9931 - val_recall: 1.0000\n",
      "Epoch 19/60\n",
      "5881/5881 [==============================] - 0s 56us/step - loss: 0.0802 - acc: 0.9619 - auc: 0.9932 - recall: 1.0000 - val_loss: 0.3253 - val_acc: 0.9245 - val_auc: 0.9932 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00019: ReduceLROnPlateau reducing learning rate to 6.25000029685907e-05.\n",
      "Epoch 20/60\n",
      "5881/5881 [==============================] - 0s 55us/step - loss: 0.0795 - acc: 0.9631 - auc: 0.9933 - recall: 1.0000 - val_loss: 0.3256 - val_acc: 0.9245 - val_auc: 0.9934 - val_recall: 1.0000\n",
      "Epoch 21/60\n",
      "5881/5881 [==============================] - 0s 57us/step - loss: 0.0771 - acc: 0.9657 - auc: 0.9935 - recall: 1.0000 - val_loss: 0.3266 - val_acc: 0.9252 - val_auc: 0.9935 - val_recall: 1.0000\n",
      "Epoch 22/60\n",
      "5881/5881 [==============================] - 0s 57us/step - loss: 0.0767 - acc: 0.9660 - auc: 0.9936 - recall: 1.0000 - val_loss: 0.3273 - val_acc: 0.9245 - val_auc: 0.9936 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00022: ReduceLROnPlateau reducing learning rate to 3.125000148429535e-05.\n",
      "Epoch 23/60\n",
      "5881/5881 [==============================] - 0s 57us/step - loss: 0.0764 - acc: 0.9670 - auc: 0.9937 - recall: 1.0000 - val_loss: 0.3269 - val_acc: 0.9239 - val_auc: 0.9938 - val_recall: 1.0000\n",
      "Restoring model weights from the end of the best epoch\n",
      "Epoch 00023: early stopping\n",
      "training time: 21.107561111450195s\n",
      "__________________________________________________________________________________________________\n",
      "Layer (type)                    Output Shape         Param #     Connected to                     \n",
      "==================================================================================================\n",
      "input_11 (InputLayer)           (None, 128, 9)       0                                            \n",
      "__________________________________________________________________________________________________\n",
      "lambda_7 (Lambda)               [(None, 128), (None, 0           input_11[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_44 (Dense)                (None, 20)           2580        lambda_7[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_45 (Dense)                (None, 20)           2580        lambda_7[0][1]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_46 (Dense)                (None, 20)           2580        lambda_7[0][2]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_47 (Dense)                (None, 20)           2580        lambda_7[0][3]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_48 (Dense)                (None, 20)           2580        lambda_7[0][4]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_49 (Dense)                (None, 20)           2580        lambda_7[0][5]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_50 (Dense)                (None, 20)           2580        lambda_7[0][6]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_51 (Dense)                (None, 20)           2580        lambda_7[0][7]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_52 (Dense)                (None, 20)           2580        lambda_7[0][8]                   \n",
      "__________________________________________________________________________________________________\n",
      "lambda_8 (Lambda)               (None, 20, 9)        0           dense_44[0][0]                   \n",
      "                                                                 dense_45[0][0]                   \n",
      "                                                                 dense_46[0][0]                   \n",
      "                                                                 dense_47[0][0]                   \n",
      "                                                                 dense_48[0][0]                   \n",
      "                                                                 dense_49[0][0]                   \n",
      "                                                                 dense_50[0][0]                   \n",
      "                                                                 dense_51[0][0]                   \n",
      "                                                                 dense_52[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "dropout_14 (Dropout)            (None, 20, 9)        0           lambda_8[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "flatten_4 (Flatten)             (None, 180)          0           dropout_14[0][0]                 \n",
      "__________________________________________________________________________________________________\n",
      "dense_53 (Dense)                (None, 250)          45250       flatten_4[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "dense_54 (Dense)                (None, 20)           5020        dense_53[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_55 (Dense)                (None, 6)            126         dense_54[0][0]                   \n",
      "==================================================================================================\n",
      "Total params: 73,616\n",
      "Trainable params: 73,616\n",
      "Non-trainable params: 0\n",
      "__________________________________________________________________________________________________\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train on 5881 samples, validate on 1471 samples\n",
      "Epoch 1/60\n",
      "5881/5881 [==============================] - 1s 241us/step - loss: 1.2196 - acc: 0.5278 - auc: 0.7142 - recall: 0.9575 - val_loss: 0.7363 - val_acc: 0.6594 - val_auc: 0.8762 - val_recall: 1.0000\n",
      "Epoch 2/60\n",
      "5881/5881 [==============================] - 0s 47us/step - loss: 0.5611 - acc: 0.7676 - auc: 0.9109 - recall: 1.0000 - val_loss: 0.5054 - val_acc: 0.8178 - val_auc: 0.9333 - val_recall: 1.0000\n",
      "Epoch 3/60\n",
      "5881/5881 [==============================] - 0s 49us/step - loss: 0.3658 - acc: 0.8594 - auc: 0.9458 - recall: 1.0000 - val_loss: 0.4145 - val_acc: 0.8776 - val_auc: 0.9552 - val_recall: 1.0000\n",
      "Epoch 4/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.2778 - acc: 0.8944 - auc: 0.9615 - recall: 1.0000 - val_loss: 0.3648 - val_acc: 0.8912 - val_auc: 0.9666 - val_recall: 1.0000\n",
      "Epoch 5/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.2408 - acc: 0.9121 - auc: 0.9702 - recall: 1.0000 - val_loss: 0.3411 - val_acc: 0.8939 - val_auc: 0.9733 - val_recall: 1.0000\n",
      "Epoch 6/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.2095 - acc: 0.9197 - auc: 0.9756 - recall: 1.0000 - val_loss: 0.3334 - val_acc: 0.8960 - val_auc: 0.9777 - val_recall: 1.0000\n",
      "Epoch 7/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.1855 - acc: 0.9333 - auc: 0.9792 - recall: 1.0000 - val_loss: 0.3047 - val_acc: 0.9123 - val_auc: 0.9807 - val_recall: 1.0000\n",
      "Epoch 8/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.1672 - acc: 0.9340 - auc: 0.9819 - recall: 1.0000 - val_loss: 0.2924 - val_acc: 0.9164 - val_auc: 0.9830 - val_recall: 1.0000\n",
      "Epoch 9/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.1553 - acc: 0.9413 - auc: 0.9840 - recall: 1.0000 - val_loss: 0.3005 - val_acc: 0.9116 - val_auc: 0.9848 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00009: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.\n",
      "Epoch 10/60\n",
      "5881/5881 [==============================] - 0s 51us/step - loss: 0.1384 - acc: 0.9454 - auc: 0.9855 - recall: 1.0000 - val_loss: 0.2916 - val_acc: 0.9150 - val_auc: 0.9862 - val_recall: 1.0000\n",
      "Epoch 11/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.1375 - acc: 0.9473 - auc: 0.9868 - recall: 1.0000 - val_loss: 0.2865 - val_acc: 0.9171 - val_auc: 0.9873 - val_recall: 1.0000\n",
      "Epoch 12/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.1307 - acc: 0.9483 - auc: 0.9878 - recall: 1.0000 - val_loss: 0.2806 - val_acc: 0.9218 - val_auc: 0.9883 - val_recall: 1.0000\n",
      "Epoch 13/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.1275 - acc: 0.9492 - auc: 0.9887 - recall: 1.0000 - val_loss: 0.2838 - val_acc: 0.9150 - val_auc: 0.9890 - val_recall: 1.0000\n",
      "Epoch 14/60\n",
      "5881/5881 [==============================] - 0s 49us/step - loss: 0.1236 - acc: 0.9526 - auc: 0.9893 - recall: 1.0000 - val_loss: 0.2788 - val_acc: 0.9218 - val_auc: 0.9896 - val_recall: 1.0000\n",
      "Epoch 15/60\n",
      "5881/5881 [==============================] - 0s 49us/step - loss: 0.1188 - acc: 0.9536 - auc: 0.9899 - recall: 1.0000 - val_loss: 0.2756 - val_acc: 0.9232 - val_auc: 0.9902 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00015: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.\n",
      "Epoch 16/60\n",
      "5881/5881 [==============================] - 0s 49us/step - loss: 0.1151 - acc: 0.9522 - auc: 0.9904 - recall: 1.0000 - val_loss: 0.2762 - val_acc: 0.9232 - val_auc: 0.9906 - val_recall: 1.0000\n",
      "Epoch 17/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.1146 - acc: 0.9539 - auc: 0.9908 - recall: 1.0000 - val_loss: 0.2794 - val_acc: 0.9225 - val_auc: 0.9910 - val_recall: 1.0000\n",
      "Epoch 18/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.1152 - acc: 0.9536 - auc: 0.9912 - recall: 1.0000 - val_loss: 0.2778 - val_acc: 0.9218 - val_auc: 0.9913 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00018: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.\n",
      "Epoch 19/60\n",
      "5881/5881 [==============================] - 0s 49us/step - loss: 0.1135 - acc: 0.9549 - auc: 0.9915 - recall: 1.0000 - val_loss: 0.2765 - val_acc: 0.9232 - val_auc: 0.9916 - val_recall: 1.0000\n",
      "Epoch 20/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.1072 - acc: 0.9560 - auc: 0.9918 - recall: 1.0000 - val_loss: 0.2777 - val_acc: 0.9232 - val_auc: 0.9919 - val_recall: 1.0000\n",
      "Epoch 21/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.1089 - acc: 0.9548 - auc: 0.9920 - recall: 1.0000 - val_loss: 0.2759 - val_acc: 0.9259 - val_auc: 0.9921 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00021: ReduceLROnPlateau reducing learning rate to 6.25000029685907e-05.\n",
      "Epoch 22/60\n",
      "5881/5881 [==============================] - 0s 51us/step - loss: 0.1085 - acc: 0.9565 - auc: 0.9922 - recall: 1.0000 - val_loss: 0.2768 - val_acc: 0.9211 - val_auc: 0.9923 - val_recall: 1.0000\n",
      "Restoring model weights from the end of the best epoch\n",
      "Epoch 00022: early stopping\n",
      "training time: 20.384784698486328s\n",
      "Train on 5881 samples, validate on 1471 samples\n",
      "Epoch 1/60\n",
      "5881/5881 [==============================] - 1s 247us/step - loss: 1.1528 - acc: 0.5778 - auc: 0.7480 - recall: 0.9575 - val_loss: 0.6658 - val_acc: 0.7519 - val_auc: 0.8962 - val_recall: 1.0000\n",
      "Epoch 2/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.4834 - acc: 0.8186 - auc: 0.9268 - recall: 1.0000 - val_loss: 0.5134 - val_acc: 0.8498 - val_auc: 0.9454 - val_recall: 1.0000\n",
      "Epoch 3/60\n",
      "5881/5881 [==============================] - 0s 49us/step - loss: 0.3163 - acc: 0.8779 - auc: 0.9555 - recall: 1.0000 - val_loss: 0.4380 - val_acc: 0.8538 - val_auc: 0.9632 - val_recall: 1.0000\n",
      "Epoch 4/60\n",
      "5881/5881 [==============================] - 0s 49us/step - loss: 0.2508 - acc: 0.9043 - auc: 0.9680 - recall: 1.0000 - val_loss: 0.3791 - val_acc: 0.8967 - val_auc: 0.9720 - val_recall: 1.0000\n",
      "Epoch 5/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.2146 - acc: 0.9254 - auc: 0.9749 - recall: 1.0000 - val_loss: 0.3627 - val_acc: 0.8892 - val_auc: 0.9773 - val_recall: 1.0000\n",
      "Epoch 6/60\n",
      "5881/5881 [==============================] - 0s 51us/step - loss: 0.1838 - acc: 0.9323 - auc: 0.9792 - recall: 1.0000 - val_loss: 0.3233 - val_acc: 0.9164 - val_auc: 0.9809 - val_recall: 1.0000\n",
      "Epoch 7/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.1623 - acc: 0.9386 - auc: 0.9823 - recall: 1.0000 - val_loss: 0.3132 - val_acc: 0.9164 - val_auc: 0.9834 - val_recall: 1.0000\n",
      "Epoch 8/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.1490 - acc: 0.9437 - auc: 0.9844 - recall: 1.0000 - val_loss: 0.3066 - val_acc: 0.9245 - val_auc: 0.9853 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00008: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.\n",
      "Epoch 9/60\n",
      "5881/5881 [==============================] - 0s 51us/step - loss: 0.1376 - acc: 0.9471 - auc: 0.9861 - recall: 1.0000 - val_loss: 0.3046 - val_acc: 0.9205 - val_auc: 0.9867 - val_recall: 1.0000\n",
      "Epoch 10/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.1308 - acc: 0.9498 - auc: 0.9873 - recall: 1.0000 - val_loss: 0.2991 - val_acc: 0.9205 - val_auc: 0.9879 - val_recall: 1.0000\n",
      "Epoch 11/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.1287 - acc: 0.9524 - auc: 0.9883 - recall: 1.0000 - val_loss: 0.3023 - val_acc: 0.9198 - val_auc: 0.9887 - val_recall: 1.0000\n",
      "Epoch 12/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.1220 - acc: 0.9546 - auc: 0.9891 - recall: 1.0000 - val_loss: 0.3047 - val_acc: 0.9164 - val_auc: 0.9895 - val_recall: 1.0000\n",
      "Epoch 13/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.1195 - acc: 0.9543 - auc: 0.9898 - recall: 1.0000 - val_loss: 0.2980 - val_acc: 0.9211 - val_auc: 0.9901 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00013: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.\n",
      "Epoch 14/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.1160 - acc: 0.9534 - auc: 0.9903 - recall: 1.0000 - val_loss: 0.2931 - val_acc: 0.9239 - val_auc: 0.9906 - val_recall: 1.0000\n",
      "Epoch 15/60\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.1111 - acc: 0.9573 - auc: 0.9908 - recall: 1.0000 - val_loss: 0.2933 - val_acc: 0.9239 - val_auc: 0.9910 - val_recall: 1.0000\n",
      "Epoch 16/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.1109 - acc: 0.9568 - auc: 0.9912 - recall: 1.0000 - val_loss: 0.2889 - val_acc: 0.9259 - val_auc: 0.9914 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00016: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.\n",
      "Epoch 17/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.1077 - acc: 0.9570 - auc: 0.9915 - recall: 1.0000 - val_loss: 0.2911 - val_acc: 0.9252 - val_auc: 0.9917 - val_recall: 1.0000\n",
      "Epoch 18/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.1127 - acc: 0.9539 - auc: 0.9918 - recall: 1.0000 - val_loss: 0.2873 - val_acc: 0.9266 - val_auc: 0.9919 - val_recall: 1.0000\n",
      "Epoch 19/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.1063 - acc: 0.9583 - auc: 0.9920 - recall: 1.0000 - val_loss: 0.2885 - val_acc: 0.9266 - val_auc: 0.9922 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00019: ReduceLROnPlateau reducing learning rate to 6.25000029685907e-05.\n",
      "Epoch 20/60\n",
      "5881/5881 [==============================] - 0s 50us/step - loss: 0.1076 - acc: 0.9585 - auc: 0.9923 - recall: 1.0000 - val_loss: 0.2890 - val_acc: 0.9245 - val_auc: 0.9924 - val_recall: 1.0000\n",
      "Restoring model weights from the end of the best epoch\n",
      "Epoch 00020: early stopping\n",
      "training time: 20.504687070846558s\n",
      "Train on 5881 samples, validate on 1471 samples\n",
      "Epoch 1/60\n",
      "5881/5881 [==============================] - 2s 256us/step - loss: 1.3022 - acc: 0.5338 - auc: 0.6745 - recall: 0.9575 - val_loss: 0.7196 - val_acc: 0.7791 - val_auc: 0.8728 - val_recall: 1.0000\n",
      "Epoch 2/60\n",
      "5881/5881 [==============================] - 0s 47us/step - loss: 0.5229 - acc: 0.8160 - auc: 0.9129 - recall: 1.0000 - val_loss: 0.5327 - val_acc: 0.8409 - val_auc: 0.9362 - val_recall: 1.0000\n",
      "Epoch 3/60\n",
      "5881/5881 [==============================] - 0s 46us/step - loss: 0.3209 - acc: 0.8743 - auc: 0.9486 - recall: 1.0000 - val_loss: 0.4679 - val_acc: 0.8606 - val_auc: 0.9579 - val_recall: 1.0000\n",
      "Epoch 4/60\n",
      "5881/5881 [==============================] - 0s 46us/step - loss: 0.2599 - acc: 0.8966 - auc: 0.9634 - recall: 1.0000 - val_loss: 0.4334 - val_acc: 0.8742 - val_auc: 0.9680 - val_recall: 1.0000\n",
      "Epoch 5/60\n",
      "5881/5881 [==============================] - 0s 46us/step - loss: 0.2140 - acc: 0.9167 - auc: 0.9713 - recall: 1.0000 - val_loss: 0.4393 - val_acc: 0.8688 - val_auc: 0.9741 - val_recall: 1.0000\n",
      "Epoch 6/60\n",
      "5881/5881 [==============================] - 0s 49us/step - loss: 0.1929 - acc: 0.9257 - auc: 0.9762 - recall: 1.0000 - val_loss: 0.4055 - val_acc: 0.8668 - val_auc: 0.9781 - val_recall: 1.0000\n",
      "Epoch 7/60\n",
      "5881/5881 [==============================] - 0s 47us/step - loss: 0.1747 - acc: 0.9328 - auc: 0.9797 - recall: 1.0000 - val_loss: 0.3898 - val_acc: 0.8838 - val_auc: 0.9810 - val_recall: 1.0000\n",
      "Epoch 8/60\n",
      "5881/5881 [==============================] - 0s 47us/step - loss: 0.1549 - acc: 0.9415 - auc: 0.9821 - recall: 1.0000 - val_loss: 0.3899 - val_acc: 0.8838 - val_auc: 0.9830 - val_recall: 1.0000\n",
      "Epoch 9/60\n",
      "5881/5881 [==============================] - 0s 47us/step - loss: 0.1457 - acc: 0.9405 - auc: 0.9839 - recall: 1.0000 - val_loss: 0.3754 - val_acc: 0.8906 - val_auc: 0.9846 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00009: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.\n",
      "Epoch 10/60\n",
      "5881/5881 [==============================] - 0s 48us/step - loss: 0.1294 - acc: 0.9498 - auc: 0.9853 - recall: 1.0000 - val_loss: 0.3751 - val_acc: 0.8906 - val_auc: 0.9859 - val_recall: 1.0000\n",
      "Epoch 11/60\n",
      "5881/5881 [==============================] - 0s 48us/step - loss: 0.1223 - acc: 0.9532 - auc: 0.9865 - recall: 1.0000 - val_loss: 0.3849 - val_acc: 0.8926 - val_auc: 0.9870 - val_recall: 1.0000\n",
      "Epoch 12/60\n",
      "5881/5881 [==============================] - 0s 48us/step - loss: 0.1176 - acc: 0.9560 - auc: 0.9874 - recall: 1.0000 - val_loss: 0.3886 - val_acc: 0.8939 - val_auc: 0.9878 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00012: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.\n",
      "Epoch 13/60\n",
      "5881/5881 [==============================] - 0s 48us/step - loss: 0.1143 - acc: 0.9541 - auc: 0.9881 - recall: 1.0000 - val_loss: 0.3827 - val_acc: 0.9001 - val_auc: 0.9885 - val_recall: 1.0000\n",
      "Epoch 14/60\n",
      "5881/5881 [==============================] - 0s 48us/step - loss: 0.1113 - acc: 0.9563 - auc: 0.9888 - recall: 1.0000 - val_loss: 0.3877 - val_acc: 0.8953 - val_auc: 0.9890 - val_recall: 1.0000\n",
      "Epoch 15/60\n",
      "5881/5881 [==============================] - 0s 48us/step - loss: 0.1110 - acc: 0.9563 - auc: 0.9893 - recall: 1.0000 - val_loss: 0.3946 - val_acc: 0.8967 - val_auc: 0.9895 - val_recall: 1.0000\n",
      "Epoch 16/60\n",
      "5881/5881 [==============================] - 0s 47us/step - loss: 0.1097 - acc: 0.9563 - auc: 0.9897 - recall: 1.0000 - val_loss: 0.3935 - val_acc: 0.8980 - val_auc: 0.9899 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00016: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.\n",
      "Epoch 17/60\n",
      "5881/5881 [==============================] - 0s 48us/step - loss: 0.1096 - acc: 0.9544 - auc: 0.9901 - recall: 1.0000 - val_loss: 0.3925 - val_acc: 0.8980 - val_auc: 0.9902 - val_recall: 1.0000\n",
      "Epoch 18/60\n",
      "5881/5881 [==============================] - 0s 47us/step - loss: 0.1053 - acc: 0.9566 - auc: 0.9904 - recall: 1.0000 - val_loss: 0.3950 - val_acc: 0.8994 - val_auc: 0.9905 - val_recall: 1.0000\n",
      "Epoch 19/60\n",
      "5881/5881 [==============================] - 0s 47us/step - loss: 0.1059 - acc: 0.9578 - auc: 0.9907 - recall: 1.0000 - val_loss: 0.4017 - val_acc: 0.9001 - val_auc: 0.9908 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00019: ReduceLROnPlateau reducing learning rate to 6.25000029685907e-05.\n",
      "Epoch 20/60\n",
      "5881/5881 [==============================] - 0s 47us/step - loss: 0.1072 - acc: 0.9565 - auc: 0.9909 - recall: 1.0000 - val_loss: 0.3973 - val_acc: 0.9001 - val_auc: 0.9910 - val_recall: 1.0000\n",
      "Epoch 21/60\n",
      "5881/5881 [==============================] - 0s 49us/step - loss: 0.1044 - acc: 0.9558 - auc: 0.9911 - recall: 1.0000 - val_loss: 0.3973 - val_acc: 0.8994 - val_auc: 0.9912 - val_recall: 1.0000\n",
      "Epoch 22/60\n",
      "5881/5881 [==============================] - 0s 48us/step - loss: 0.1051 - acc: 0.9561 - auc: 0.9913 - recall: 1.0000 - val_loss: 0.4009 - val_acc: 0.9007 - val_auc: 0.9914 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00022: ReduceLROnPlateau reducing learning rate to 3.125000148429535e-05.\n",
      "Epoch 23/60\n",
      "5881/5881 [==============================] - 0s 47us/step - loss: 0.1019 - acc: 0.9566 - auc: 0.9915 - recall: 1.0000 - val_loss: 0.4000 - val_acc: 0.9001 - val_auc: 0.9915 - val_recall: 1.0000\n",
      "Restoring model weights from the end of the best epoch\n",
      "Epoch 00023: early stopping\n",
      "training time: 22.53015947341919s\n",
      "__________________________________________________________________________________________________\n",
      "Layer (type)                    Output Shape         Param #     Connected to                     \n",
      "==================================================================================================\n",
      "input_14 (InputLayer)           (None, 128, 9)       0                                            \n",
      "__________________________________________________________________________________________________\n",
      "lambda_13 (Lambda)              [(None, 128), (None, 0           input_14[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_80 (Dense)                (None, 20)           2580        lambda_13[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "dense_81 (Dense)                (None, 20)           2580        lambda_13[0][1]                  \n",
      "__________________________________________________________________________________________________\n",
      "dense_82 (Dense)                (None, 20)           2580        lambda_13[0][2]                  \n",
      "__________________________________________________________________________________________________\n",
      "dense_83 (Dense)                (None, 20)           2580        lambda_13[0][3]                  \n",
      "__________________________________________________________________________________________________\n",
      "dense_84 (Dense)                (None, 20)           2580        lambda_13[0][4]                  \n",
      "__________________________________________________________________________________________________\n",
      "dense_85 (Dense)                (None, 20)           2580        lambda_13[0][5]                  \n",
      "__________________________________________________________________________________________________\n",
      "dense_86 (Dense)                (None, 20)           2580        lambda_13[0][6]                  \n",
      "__________________________________________________________________________________________________\n",
      "dense_87 (Dense)                (None, 20)           2580        lambda_13[0][7]                  \n",
      "__________________________________________________________________________________________________\n",
      "dense_88 (Dense)                (None, 20)           2580        lambda_13[0][8]                  \n",
      "__________________________________________________________________________________________________\n",
      "lambda_14 (Lambda)              (None, 20, 9)        0           dense_80[0][0]                   \n",
      "                                                                 dense_81[0][0]                   \n",
      "                                                                 dense_82[0][0]                   \n",
      "                                                                 dense_83[0][0]                   \n",
      "                                                                 dense_84[0][0]                   \n",
      "                                                                 dense_85[0][0]                   \n",
      "                                                                 dense_86[0][0]                   \n",
      "                                                                 dense_87[0][0]                   \n",
      "                                                                 dense_88[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "lstm_10 (LSTM)                  (None, 150)          96000       input_14[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "dropout_17 (Dropout)            (None, 20, 9)        0           lambda_14[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "dropout_18 (Dropout)            (None, 150)          0           lstm_10[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "flatten_7 (Flatten)             (None, 180)          0           dropout_17[0][0]                 \n",
      "__________________________________________________________________________________________________\n",
      "dense_92 (Dense)                (None, 150)          22650       dropout_18[0][0]                 \n",
      "__________________________________________________________________________________________________\n",
      "dense_89 (Dense)                (None, 250)          45250       flatten_7[0][0]                  \n",
      "__________________________________________________________________________________________________\n",
      "concatenate_1 (Concatenate)     (None, 400)          0           dense_92[0][0]                   \n",
      "                                                                 dense_89[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_93 (Dense)                (None, 6)            2406        concatenate_1[0][0]              \n",
      "==================================================================================================\n",
      "Total params: 189,526\n",
      "Trainable params: 189,526\n",
      "Non-trainable params: 0\n",
      "__________________________________________________________________________________________________\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train on 5881 samples, validate on 1471 samples\n",
      "Epoch 1/60\n",
      "5881/5881 [==============================] - 8s 1ms/step - loss: 1.3059 - acc: 0.5681 - auc: 0.7149 - recall: 0.9563 - val_loss: 0.7424 - val_acc: 0.7492 - val_auc: 0.8863 - val_recall: 0.9941\n",
      "Epoch 2/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 1.4624 - acc: 0.7665 - auc: 0.9065 - recall: 0.9835 - val_loss: 2.2352 - val_acc: 0.7308 - val_auc: 0.9088 - val_recall: 0.9660\n",
      "Epoch 3/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.7670 - acc: 0.8473 - auc: 0.9171 - recall: 0.9633 - val_loss: 2.0506 - val_acc: 0.7349 - val_auc: 0.9267 - val_recall: 0.9643\n",
      "Epoch 4/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.4437 - acc: 0.8898 - auc: 0.9318 - recall: 0.9637 - val_loss: 0.4475 - val_acc: 0.8559 - val_auc: 0.9405 - val_recall: 0.9680\n",
      "Epoch 5/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.2651 - acc: 0.9146 - auc: 0.9468 - recall: 0.9713 - val_loss: 0.4139 - val_acc: 0.8668 - val_auc: 0.9522 - val_recall: 0.9741\n",
      "Epoch 6/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.2299 - acc: 0.9279 - auc: 0.9564 - recall: 0.9762 - val_loss: 0.4037 - val_acc: 0.8736 - val_auc: 0.9601 - val_recall: 0.9782\n",
      "Epoch 7/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.2126 - acc: 0.9352 - auc: 0.9631 - recall: 0.9797 - val_loss: 0.3933 - val_acc: 0.8804 - val_auc: 0.9656 - val_recall: 0.9810\n",
      "Epoch 8/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1956 - acc: 0.9395 - auc: 0.9678 - recall: 0.9822 - val_loss: 0.3770 - val_acc: 0.8892 - val_auc: 0.9697 - val_recall: 0.9832\n",
      "Epoch 9/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1640 - acc: 0.9390 - auc: 0.9714 - recall: 0.9842 - val_loss: 0.3628 - val_acc: 0.8885 - val_auc: 0.9729 - val_recall: 0.9850\n",
      "Epoch 10/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.1511 - acc: 0.9452 - auc: 0.9742 - recall: 0.9858 - val_loss: 0.3504 - val_acc: 0.8939 - val_auc: 0.9755 - val_recall: 0.9865\n",
      "\n",
      "Epoch 00010: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.\n",
      "Epoch 11/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1336 - acc: 0.9519 - auc: 0.9766 - recall: 0.9872 - val_loss: 0.3304 - val_acc: 0.9014 - val_auc: 0.9776 - val_recall: 0.9878\n",
      "Epoch 12/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1281 - acc: 0.9524 - auc: 0.9785 - recall: 0.9883 - val_loss: 0.3189 - val_acc: 0.9001 - val_auc: 0.9794 - val_recall: 0.9888\n",
      "Epoch 13/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.1505 - acc: 0.9534 - auc: 0.9801 - recall: 0.9892 - val_loss: 0.3786 - val_acc: 0.8980 - val_auc: 0.9807 - val_recall: 0.9895\n",
      "Epoch 14/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1902 - acc: 0.9517 - auc: 0.9812 - recall: 0.9896 - val_loss: 0.3214 - val_acc: 0.9035 - val_auc: 0.9817 - val_recall: 0.9900\n",
      "\n",
      "Epoch 00014: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.\n",
      "Epoch 15/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1156 - acc: 0.9575 - auc: 0.9823 - recall: 0.9903 - val_loss: 0.3251 - val_acc: 0.9014 - val_auc: 0.9828 - val_recall: 0.9906\n",
      "Epoch 16/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1126 - acc: 0.9561 - auc: 0.9833 - recall: 0.9909 - val_loss: 0.3209 - val_acc: 0.9028 - val_auc: 0.9837 - val_recall: 0.9912\n",
      "Epoch 17/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1116 - acc: 0.9541 - auc: 0.9842 - recall: 0.9915 - val_loss: 0.3164 - val_acc: 0.9021 - val_auc: 0.9846 - val_recall: 0.9918\n",
      "\n",
      "Epoch 00017: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.\n",
      "Epoch 18/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1094 - acc: 0.9570 - auc: 0.9849 - recall: 0.9920 - val_loss: 0.3193 - val_acc: 0.9048 - val_auc: 0.9853 - val_recall: 0.9922\n",
      "Epoch 19/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1104 - acc: 0.9583 - auc: 0.9856 - recall: 0.9924 - val_loss: 0.3211 - val_acc: 0.9007 - val_auc: 0.9859 - val_recall: 0.9926\n",
      "Epoch 20/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1098 - acc: 0.9554 - auc: 0.9862 - recall: 0.9928 - val_loss: 0.3184 - val_acc: 0.9035 - val_auc: 0.9865 - val_recall: 0.9930\n",
      "\n",
      "Epoch 00020: ReduceLROnPlateau reducing learning rate to 6.25000029685907e-05.\n",
      "Epoch 21/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.1067 - acc: 0.9582 - auc: 0.9867 - recall: 0.9932 - val_loss: 0.3194 - val_acc: 0.9028 - val_auc: 0.9870 - val_recall: 0.9933\n",
      "Restoring model weights from the end of the best epoch\n",
      "Epoch 00021: early stopping\n",
      "training time: 155.91726851463318s\n",
      "Train on 5881 samples, validate on 1471 samples\n",
      "Epoch 1/60\n",
      "5881/5881 [==============================] - 9s 1ms/step - loss: 1.4477 - acc: 0.6195 - auc: 0.8052 - recall: 0.9534 - val_loss: 0.6318 - val_acc: 0.8171 - val_auc: 0.8996 - val_recall: 0.9779\n",
      "Epoch 2/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.4665 - acc: 0.8250 - auc: 0.9280 - recall: 0.9855 - val_loss: 0.5011 - val_acc: 0.8491 - val_auc: 0.9460 - val_recall: 0.9897\n",
      "Epoch 3/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.3281 - acc: 0.8750 - auc: 0.9550 - recall: 0.9918 - val_loss: 0.3967 - val_acc: 0.8756 - val_auc: 0.9620 - val_recall: 0.9933\n",
      "Epoch 4/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.2449 - acc: 0.9157 - auc: 0.9669 - recall: 0.9942 - val_loss: 0.3406 - val_acc: 0.8912 - val_auc: 0.9712 - val_recall: 0.9950\n",
      "Epoch 5/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.2180 - acc: 0.9264 - auc: 0.9742 - recall: 0.9955 - val_loss: 0.4218 - val_acc: 0.8967 - val_auc: 0.9766 - val_recall: 0.9958\n",
      "Epoch 6/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.2228 - acc: 0.9322 - auc: 0.9783 - recall: 0.9958 - val_loss: 0.3494 - val_acc: 0.9021 - val_auc: 0.9799 - val_recall: 0.9960\n",
      "Epoch 7/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.2012 - acc: 0.9383 - auc: 0.9812 - recall: 0.9961 - val_loss: 0.3625 - val_acc: 0.8987 - val_auc: 0.9822 - val_recall: 0.9962\n",
      "Epoch 8/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.2120 - acc: 0.9424 - auc: 0.9831 - recall: 0.9962 - val_loss: 0.4353 - val_acc: 0.9075 - val_auc: 0.9838 - val_recall: 0.9962\n",
      "\n",
      "Epoch 00008: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.\n",
      "Epoch 9/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.1902 - acc: 0.9424 - auc: 0.9844 - recall: 0.9960 - val_loss: 0.2903 - val_acc: 0.9089 - val_auc: 0.9851 - val_recall: 0.9962\n",
      "Epoch 10/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1341 - acc: 0.9492 - auc: 0.9858 - recall: 0.9964 - val_loss: 0.2922 - val_acc: 0.9171 - val_auc: 0.9864 - val_recall: 0.9965\n",
      "Epoch 11/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.1259 - acc: 0.9510 - auc: 0.9869 - recall: 0.9967 - val_loss: 0.3025 - val_acc: 0.9116 - val_auc: 0.9874 - val_recall: 0.9969\n",
      "Epoch 12/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.1245 - acc: 0.9541 - auc: 0.9878 - recall: 0.9970 - val_loss: 0.2939 - val_acc: 0.9143 - val_auc: 0.9883 - val_recall: 0.9971\n",
      "Epoch 13/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.1196 - acc: 0.9551 - auc: 0.9886 - recall: 0.9972 - val_loss: 0.2918 - val_acc: 0.9205 - val_auc: 0.9890 - val_recall: 0.9973\n",
      "Epoch 14/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1144 - acc: 0.9556 - auc: 0.9893 - recall: 0.9974 - val_loss: 0.2932 - val_acc: 0.9177 - val_auc: 0.9896 - val_recall: 0.9975\n",
      "\n",
      "Epoch 00014: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.\n",
      "Epoch 15/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.1149 - acc: 0.9548 - auc: 0.9898 - recall: 0.9976 - val_loss: 0.3012 - val_acc: 0.9116 - val_auc: 0.9901 - val_recall: 0.9977\n",
      "Epoch 16/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.1113 - acc: 0.9568 - auc: 0.9903 - recall: 0.9978 - val_loss: 0.2938 - val_acc: 0.9143 - val_auc: 0.9905 - val_recall: 0.9979\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 17/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.1097 - acc: 0.9573 - auc: 0.9907 - recall: 0.9979 - val_loss: 0.2921 - val_acc: 0.9089 - val_auc: 0.9909 - val_recall: 0.9980\n",
      "\n",
      "Epoch 00017: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.\n",
      "Epoch 18/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1106 - acc: 0.9589 - auc: 0.9911 - recall: 0.9980 - val_loss: 0.3015 - val_acc: 0.9089 - val_auc: 0.9912 - val_recall: 0.9981\n",
      "Epoch 19/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.1079 - acc: 0.9568 - auc: 0.9914 - recall: 0.9981 - val_loss: 0.2955 - val_acc: 0.9157 - val_auc: 0.9915 - val_recall: 0.9982\n",
      "Epoch 20/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1070 - acc: 0.9568 - auc: 0.9916 - recall: 0.9982 - val_loss: 0.2934 - val_acc: 0.9164 - val_auc: 0.9918 - val_recall: 0.9983\n",
      "\n",
      "Epoch 00020: ReduceLROnPlateau reducing learning rate to 6.25000029685907e-05.\n",
      "Epoch 21/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1076 - acc: 0.9573 - auc: 0.9919 - recall: 0.9983 - val_loss: 0.2940 - val_acc: 0.9157 - val_auc: 0.9920 - val_recall: 0.9984\n",
      "Restoring model weights from the end of the best epoch\n",
      "Epoch 00021: early stopping\n",
      "training time: 157.6658275127411s\n",
      "Train on 5881 samples, validate on 1471 samples\n",
      "Epoch 1/60\n",
      "5881/5881 [==============================] - 9s 1ms/step - loss: 1.3190 - acc: 0.6251 - auc: 0.8018 - recall: 0.9562 - val_loss: 0.7225 - val_acc: 0.7254 - val_auc: 0.9041 - val_recall: 0.9865\n",
      "Epoch 2/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.5088 - acc: 0.8050 - auc: 0.9275 - recall: 0.9912 - val_loss: 0.5307 - val_acc: 0.8185 - val_auc: 0.9445 - val_recall: 0.9937\n",
      "Epoch 3/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.3713 - acc: 0.8677 - auc: 0.9535 - recall: 0.9949 - val_loss: 0.4618 - val_acc: 0.8396 - val_auc: 0.9603 - val_recall: 0.9953\n",
      "Epoch 4/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.2698 - acc: 0.8992 - auc: 0.9652 - recall: 0.9960 - val_loss: 0.3973 - val_acc: 0.8600 - val_auc: 0.9692 - val_recall: 0.9965\n",
      "Epoch 5/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.2237 - acc: 0.9129 - auc: 0.9724 - recall: 0.9969 - val_loss: 0.3682 - val_acc: 0.8770 - val_auc: 0.9750 - val_recall: 0.9972\n",
      "Epoch 6/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1957 - acc: 0.9288 - auc: 0.9771 - recall: 0.9975 - val_loss: 0.3525 - val_acc: 0.8919 - val_auc: 0.9789 - val_recall: 0.9977\n",
      "Epoch 7/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1781 - acc: 0.9373 - auc: 0.9803 - recall: 0.9979 - val_loss: 0.3450 - val_acc: 0.8939 - val_auc: 0.9816 - val_recall: 0.9980\n",
      "Epoch 8/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1636 - acc: 0.9390 - auc: 0.9827 - recall: 0.9981 - val_loss: 0.3427 - val_acc: 0.8919 - val_auc: 0.9836 - val_recall: 0.9983\n",
      "\n",
      "Epoch 00008: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.\n",
      "Epoch 9/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1554 - acc: 0.9435 - auc: 0.9844 - recall: 0.9984 - val_loss: 0.3317 - val_acc: 0.8980 - val_auc: 0.9851 - val_recall: 0.9985\n",
      "Epoch 10/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.2159 - acc: 0.9447 - auc: 0.9857 - recall: 0.9984 - val_loss: 0.3369 - val_acc: 0.8919 - val_auc: 0.9861 - val_recall: 0.9982\n",
      "Epoch 11/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.2806 - acc: 0.9415 - auc: 0.9864 - recall: 0.9980 - val_loss: 0.3565 - val_acc: 0.8912 - val_auc: 0.9866 - val_recall: 0.9977\n",
      "Epoch 12/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.2908 - acc: 0.9410 - auc: 0.9868 - recall: 0.9975 - val_loss: 0.4250 - val_acc: 0.8906 - val_auc: 0.9869 - val_recall: 0.9972\n",
      "\n",
      "Epoch 00012: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.\n",
      "Epoch 13/60\n",
      "5881/5881 [==============================] - 6s 1ms/step - loss: 0.2363 - acc: 0.9442 - auc: 0.9870 - recall: 0.9970 - val_loss: 0.3298 - val_acc: 0.8892 - val_auc: 0.9873 - val_recall: 0.9969\n",
      "Epoch 14/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1319 - acc: 0.9509 - auc: 0.9877 - recall: 0.9970 - val_loss: 0.3199 - val_acc: 0.8967 - val_auc: 0.9880 - val_recall: 0.9971\n",
      "Epoch 15/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1261 - acc: 0.9551 - auc: 0.9883 - recall: 0.9972 - val_loss: 0.3195 - val_acc: 0.8946 - val_auc: 0.9886 - val_recall: 0.9973\n",
      "\n",
      "Epoch 00015: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.\n",
      "Epoch 16/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1266 - acc: 0.9524 - auc: 0.9889 - recall: 0.9974 - val_loss: 0.3219 - val_acc: 0.8987 - val_auc: 0.9891 - val_recall: 0.9975\n",
      "Epoch 17/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1228 - acc: 0.9551 - auc: 0.9893 - recall: 0.9976 - val_loss: 0.3208 - val_acc: 0.8994 - val_auc: 0.9896 - val_recall: 0.9976\n",
      "Epoch 18/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1209 - acc: 0.9551 - auc: 0.9898 - recall: 0.9977 - val_loss: 0.3193 - val_acc: 0.8967 - val_auc: 0.9900 - val_recall: 0.9977\n",
      "\n",
      "Epoch 00018: ReduceLROnPlateau reducing learning rate to 6.25000029685907e-05.\n",
      "Epoch 19/60\n",
      "5881/5881 [==============================] - 7s 1ms/step - loss: 0.1216 - acc: 0.9558 - auc: 0.9901 - recall: 0.9978 - val_loss: 0.3190 - val_acc: 0.8973 - val_auc: 0.9903 - val_recall: 0.9979\n",
      "Restoring model weights from the end of the best epoch\n",
      "Epoch 00019: early stopping\n",
      "training time: 145.94875741004944s\n",
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "input_17 (InputLayer)        (None, 128, 9)            0         \n",
      "_________________________________________________________________\n",
      "dense_122 (Dense)            (None, 128, 250)          2500      \n",
      "_________________________________________________________________\n",
      "dropout_23 (Dropout)         (None, 128, 250)          0         \n",
      "_________________________________________________________________\n",
      "dense_123 (Dense)            (None, 128, 250)          62750     \n",
      "_________________________________________________________________\n",
      "dropout_24 (Dropout)         (None, 128, 250)          0         \n",
      "_________________________________________________________________\n",
      "dense_124 (Dense)            (None, 128, 30)           7530      \n",
      "_________________________________________________________________\n",
      "flatten_10 (Flatten)         (None, 3840)              0         \n",
      "_________________________________________________________________\n",
      "dense_125 (Dense)            (None, 6)                 23046     \n",
      "=================================================================\n",
      "Total params: 95,826\n",
      "Trainable params: 95,826\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n",
      "Train on 5881 samples, validate on 1471 samples\n",
      "Epoch 1/60\n",
      "5881/5881 [==============================] - 5s 809us/step - loss: 1.1009 - acc: 0.5530 - auc: 0.7329 - recall: 0.9575 - val_loss: 1.0442 - val_acc: 0.6893 - val_auc: 0.8902 - val_recall: 1.0000\n",
      "Epoch 2/60\n",
      "5881/5881 [==============================] - 3s 584us/step - loss: 0.5196 - acc: 0.7723 - auc: 0.9182 - recall: 1.0000 - val_loss: 0.8964 - val_acc: 0.7641 - val_auc: 0.9352 - val_recall: 1.0000\n",
      "Epoch 3/60\n",
      "5881/5881 [==============================] - 3s 572us/step - loss: 0.4021 - acc: 0.8390 - auc: 0.9451 - recall: 1.0000 - val_loss: 0.7785 - val_acc: 0.8382 - val_auc: 0.9529 - val_recall: 1.0000\n",
      "Epoch 4/60\n",
      "5881/5881 [==============================] - 3s 572us/step - loss: 0.3316 - acc: 0.8721 - auc: 0.9585 - recall: 1.0000 - val_loss: 0.7293 - val_acc: 0.8742 - val_auc: 0.9628 - val_recall: 1.0000\n",
      "Epoch 5/60\n",
      "5881/5881 [==============================] - 3s 571us/step - loss: 0.2809 - acc: 0.8930 - auc: 0.9662 - recall: 1.0000 - val_loss: 0.7018 - val_acc: 0.8715 - val_auc: 0.9690 - val_recall: 1.0000\n",
      "Epoch 6/60\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5881/5881 [==============================] - 3s 568us/step - loss: 0.2351 - acc: 0.9155 - auc: 0.9713 - recall: 1.0000 - val_loss: 0.6875 - val_acc: 0.8838 - val_auc: 0.9734 - val_recall: 1.0000\n",
      "Epoch 7/60\n",
      "5881/5881 [==============================] - 3s 572us/step - loss: 0.1891 - acc: 0.9337 - auc: 0.9752 - recall: 1.0000 - val_loss: 0.7050 - val_acc: 0.8749 - val_auc: 0.9767 - val_recall: 1.0000\n",
      "Epoch 8/60\n",
      "5881/5881 [==============================] - 3s 575us/step - loss: 0.1890 - acc: 0.9281 - auc: 0.9778 - recall: 1.0000 - val_loss: 0.6712 - val_acc: 0.8939 - val_auc: 0.9789 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00008: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.\n",
      "Epoch 9/60\n",
      "5881/5881 [==============================] - 3s 569us/step - loss: 0.1502 - acc: 0.9434 - auc: 0.9799 - recall: 1.0000 - val_loss: 0.6574 - val_acc: 0.9069 - val_auc: 0.9809 - val_recall: 1.0000\n",
      "Epoch 10/60\n",
      "5881/5881 [==============================] - 3s 571us/step - loss: 0.1367 - acc: 0.9449 - auc: 0.9817 - recall: 1.0000 - val_loss: 0.6578 - val_acc: 0.9089 - val_auc: 0.9824 - val_recall: 1.0000\n",
      "Epoch 11/60\n",
      "5881/5881 [==============================] - 3s 568us/step - loss: 0.1304 - acc: 0.9498 - auc: 0.9831 - recall: 1.0000 - val_loss: 0.6675 - val_acc: 0.8987 - val_auc: 0.9837 - val_recall: 1.0000\n",
      "Epoch 12/60\n",
      "5881/5881 [==============================] - 3s 572us/step - loss: 0.1263 - acc: 0.9495 - auc: 0.9842 - recall: 1.0000 - val_loss: 0.6583 - val_acc: 0.9089 - val_auc: 0.9847 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00012: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.\n",
      "Epoch 13/60\n",
      "5881/5881 [==============================] - 3s 569us/step - loss: 0.1221 - acc: 0.9481 - auc: 0.9852 - recall: 1.0000 - val_loss: 0.6574 - val_acc: 0.9075 - val_auc: 0.9855 - val_recall: 1.0000\n",
      "Epoch 14/60\n",
      "5881/5881 [==============================] - 3s 570us/step - loss: 0.1150 - acc: 0.9546 - auc: 0.9859 - recall: 1.0000 - val_loss: 0.6667 - val_acc: 0.9069 - val_auc: 0.9862 - val_recall: 1.0000\n",
      "Epoch 15/60\n",
      "5881/5881 [==============================] - 3s 562us/step - loss: 0.1168 - acc: 0.9519 - auc: 0.9865 - recall: 1.0000 - val_loss: 0.6599 - val_acc: 0.9075 - val_auc: 0.9868 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00015: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.\n",
      "Epoch 16/60\n",
      "5881/5881 [==============================] - 3s 572us/step - loss: 0.1105 - acc: 0.9543 - auc: 0.9871 - recall: 1.0000 - val_loss: 0.6591 - val_acc: 0.9082 - val_auc: 0.9873 - val_recall: 1.0000\n",
      "Epoch 17/60\n",
      "5881/5881 [==============================] - 3s 568us/step - loss: 0.1092 - acc: 0.9553 - auc: 0.9876 - recall: 1.0000 - val_loss: 0.6663 - val_acc: 0.9048 - val_auc: 0.9877 - val_recall: 1.0000\n",
      "Epoch 18/60\n",
      "5881/5881 [==============================] - 3s 571us/step - loss: 0.1080 - acc: 0.9554 - auc: 0.9879 - recall: 1.0000 - val_loss: 0.6564 - val_acc: 0.9096 - val_auc: 0.9881 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00018: ReduceLROnPlateau reducing learning rate to 6.25000029685907e-05.\n",
      "Epoch 19/60\n",
      "5881/5881 [==============================] - 3s 567us/step - loss: 0.1076 - acc: 0.9548 - auc: 0.9883 - recall: 1.0000 - val_loss: 0.6582 - val_acc: 0.9089 - val_auc: 0.9884 - val_recall: 1.0000\n",
      "Restoring model weights from the end of the best epoch\n",
      "Epoch 00019: early stopping\n",
      "training time: 84.30107402801514s\n",
      "Train on 5881 samples, validate on 1471 samples\n",
      "Epoch 1/60\n",
      "5881/5881 [==============================] - 5s 790us/step - loss: 1.0907 - acc: 0.5786 - auc: 0.7418 - recall: 0.9575 - val_loss: 0.8389 - val_acc: 0.7498 - val_auc: 0.8973 - val_recall: 1.0000\n",
      "Epoch 2/60\n",
      "5881/5881 [==============================] - 3s 571us/step - loss: 0.5133 - acc: 0.7735 - auc: 0.9232 - recall: 1.0000 - val_loss: 0.7191 - val_acc: 0.7634 - val_auc: 0.9383 - val_recall: 1.0000\n",
      "Epoch 3/60\n",
      "5881/5881 [==============================] - 3s 563us/step - loss: 0.4139 - acc: 0.8267 - auc: 0.9463 - recall: 1.0000 - val_loss: 0.5916 - val_acc: 0.8443 - val_auc: 0.9538 - val_recall: 1.0000\n",
      "Epoch 4/60\n",
      "5881/5881 [==============================] - 3s 571us/step - loss: 0.3385 - acc: 0.8708 - auc: 0.9589 - recall: 1.0000 - val_loss: 0.5904 - val_acc: 0.8498 - val_auc: 0.9630 - val_recall: 1.0000\n",
      "Epoch 5/60\n",
      "5881/5881 [==============================] - 3s 566us/step - loss: 0.2828 - acc: 0.8925 - auc: 0.9661 - recall: 1.0000 - val_loss: 0.5471 - val_acc: 0.8872 - val_auc: 0.9690 - val_recall: 1.0000\n",
      "Epoch 6/60\n",
      "5881/5881 [==============================] - 3s 559us/step - loss: 0.2333 - acc: 0.9163 - auc: 0.9714 - recall: 1.0000 - val_loss: 0.6113 - val_acc: 0.8545 - val_auc: 0.9734 - val_recall: 1.0000\n",
      "Epoch 7/60\n",
      "5881/5881 [==============================] - 3s 560us/step - loss: 0.2115 - acc: 0.9153 - auc: 0.9749 - recall: 1.0000 - val_loss: 0.5616 - val_acc: 0.8858 - val_auc: 0.9764 - val_recall: 1.0000\n",
      "Epoch 8/60\n",
      "5881/5881 [==============================] - 3s 568us/step - loss: 0.1724 - acc: 0.9344 - auc: 0.9778 - recall: 1.0000 - val_loss: 0.5704 - val_acc: 0.8967 - val_auc: 0.9789 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00008: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.\n",
      "Epoch 9/60\n",
      "5881/5881 [==============================] - 3s 569us/step - loss: 0.1537 - acc: 0.9437 - auc: 0.9800 - recall: 1.0000 - val_loss: 0.6190 - val_acc: 0.8987 - val_auc: 0.9809 - val_recall: 1.0000\n",
      "Epoch 10/60\n",
      "5881/5881 [==============================] - 3s 566us/step - loss: 0.1418 - acc: 0.9485 - auc: 0.9818 - recall: 1.0000 - val_loss: 0.6251 - val_acc: 0.8973 - val_auc: 0.9825 - val_recall: 1.0000\n",
      "Epoch 11/60\n",
      "5881/5881 [==============================] - 3s 565us/step - loss: 0.1355 - acc: 0.9466 - auc: 0.9831 - recall: 1.0000 - val_loss: 0.6386 - val_acc: 0.9055 - val_auc: 0.9837 - val_recall: 1.0000\n",
      "Epoch 12/60\n",
      "5881/5881 [==============================] - 3s 566us/step - loss: 0.1248 - acc: 0.9522 - auc: 0.9843 - recall: 1.0000 - val_loss: 0.6440 - val_acc: 0.8980 - val_auc: 0.9847 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00012: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.\n",
      "Epoch 13/60\n",
      "5881/5881 [==============================] - 3s 566us/step - loss: 0.1208 - acc: 0.9544 - auc: 0.9851 - recall: 1.0000 - val_loss: 0.6592 - val_acc: 0.9041 - val_auc: 0.9855 - val_recall: 1.0000\n",
      "Epoch 14/60\n",
      "5881/5881 [==============================] - 3s 569us/step - loss: 0.1138 - acc: 0.9568 - auc: 0.9859 - recall: 1.0000 - val_loss: 0.6565 - val_acc: 0.9082 - val_auc: 0.9862 - val_recall: 1.0000\n",
      "Epoch 15/60\n",
      "5881/5881 [==============================] - 3s 567us/step - loss: 0.1118 - acc: 0.9575 - auc: 0.9865 - recall: 1.0000 - val_loss: 0.6584 - val_acc: 0.9028 - val_auc: 0.9868 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00015: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.\n",
      "Epoch 16/60\n",
      "5881/5881 [==============================] - 3s 566us/step - loss: 0.1119 - acc: 0.9548 - auc: 0.9870 - recall: 1.0000 - val_loss: 0.6705 - val_acc: 0.9075 - val_auc: 0.9873 - val_recall: 1.0000\n",
      "Epoch 17/60\n",
      "5881/5881 [==============================] - 3s 569us/step - loss: 0.1076 - acc: 0.9548 - auc: 0.9875 - recall: 1.0000 - val_loss: 0.6738 - val_acc: 0.9069 - val_auc: 0.9877 - val_recall: 1.0000\n",
      "Epoch 18/60\n",
      "5881/5881 [==============================] - 3s 569us/step - loss: 0.1070 - acc: 0.9592 - auc: 0.9879 - recall: 1.0000 - val_loss: 0.6751 - val_acc: 0.9082 - val_auc: 0.9881 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00018: ReduceLROnPlateau reducing learning rate to 6.25000029685907e-05.\n",
      "Epoch 19/60\n",
      "5881/5881 [==============================] - 3s 568us/step - loss: 0.1039 - acc: 0.9583 - auc: 0.9883 - recall: 1.0000 - val_loss: 0.6726 - val_acc: 0.9075 - val_auc: 0.9884 - val_recall: 1.0000\n",
      "Restoring model weights from the end of the best epoch\n",
      "Epoch 00019: early stopping\n",
      "training time: 83.7048978805542s\n",
      "Train on 5881 samples, validate on 1471 samples\n",
      "Epoch 1/60\n",
      "5881/5881 [==============================] - 5s 787us/step - loss: 1.1639 - acc: 0.5242 - auc: 0.7073 - recall: 0.9575 - val_loss: 0.8068 - val_acc: 0.7104 - val_auc: 0.8765 - val_recall: 1.0000\n",
      "Epoch 2/60\n",
      "5881/5881 [==============================] - 3s 561us/step - loss: 0.5071 - acc: 0.7781 - auc: 0.9126 - recall: 1.0000 - val_loss: 0.7209 - val_acc: 0.7356 - val_auc: 0.9327 - val_recall: 1.0000\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 3/60\n",
      "5881/5881 [==============================] - 3s 564us/step - loss: 0.3983 - acc: 0.8417 - auc: 0.9429 - recall: 1.0000 - val_loss: 0.6373 - val_acc: 0.8389 - val_auc: 0.9515 - val_recall: 1.0000\n",
      "Epoch 4/60\n",
      "5881/5881 [==============================] - 3s 565us/step - loss: 0.3223 - acc: 0.8777 - auc: 0.9573 - recall: 1.0000 - val_loss: 0.6238 - val_acc: 0.8647 - val_auc: 0.9620 - val_recall: 1.0000\n",
      "Epoch 5/60\n",
      "5881/5881 [==============================] - 3s 563us/step - loss: 0.2777 - acc: 0.8953 - auc: 0.9654 - recall: 1.0000 - val_loss: 0.6893 - val_acc: 0.8688 - val_auc: 0.9682 - val_recall: 1.0000\n",
      "Epoch 6/60\n",
      "5881/5881 [==============================] - 3s 563us/step - loss: 0.2332 - acc: 0.9114 - auc: 0.9706 - recall: 1.0000 - val_loss: 0.6565 - val_acc: 0.8960 - val_auc: 0.9727 - val_recall: 1.0000\n",
      "Epoch 7/60\n",
      "5881/5881 [==============================] - 3s 564us/step - loss: 0.1783 - acc: 0.9376 - auc: 0.9747 - recall: 1.0000 - val_loss: 0.6742 - val_acc: 0.9041 - val_auc: 0.9763 - val_recall: 1.0000\n",
      "Epoch 8/60\n",
      "5881/5881 [==============================] - 3s 565us/step - loss: 0.1622 - acc: 0.9359 - auc: 0.9776 - recall: 1.0000 - val_loss: 0.6845 - val_acc: 0.8994 - val_auc: 0.9788 - val_recall: 1.0000\n",
      "Epoch 9/60\n",
      "5881/5881 [==============================] - 3s 565us/step - loss: 0.1532 - acc: 0.9393 - auc: 0.9798 - recall: 1.0000 - val_loss: 0.6820 - val_acc: 0.9001 - val_auc: 0.9807 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00009: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.\n",
      "Epoch 10/60\n",
      "5881/5881 [==============================] - 3s 565us/step - loss: 0.1250 - acc: 0.9515 - auc: 0.9816 - recall: 1.0000 - val_loss: 0.6715 - val_acc: 0.9082 - val_auc: 0.9823 - val_recall: 1.0000\n",
      "Epoch 11/60\n",
      "5881/5881 [==============================] - 3s 560us/step - loss: 0.1145 - acc: 0.9558 - auc: 0.9829 - recall: 1.0000 - val_loss: 0.6683 - val_acc: 0.9041 - val_auc: 0.9835 - val_recall: 1.0000\n",
      "Epoch 12/60\n",
      "5881/5881 [==============================] - 3s 574us/step - loss: 0.1120 - acc: 0.9582 - auc: 0.9841 - recall: 1.0000 - val_loss: 0.6621 - val_acc: 0.9089 - val_auc: 0.9845 - val_recall: 1.0000\n",
      "Epoch 13/60\n",
      "5881/5881 [==============================] - 3s 578us/step - loss: 0.1079 - acc: 0.9568 - auc: 0.9850 - recall: 1.0000 - val_loss: 0.6669 - val_acc: 0.9055 - val_auc: 0.9853 - val_recall: 1.0000\n",
      "Epoch 14/60\n",
      "5881/5881 [==============================] - 3s 562us/step - loss: 0.1098 - acc: 0.9578 - auc: 0.9857 - recall: 1.0000 - val_loss: 0.6788 - val_acc: 0.9082 - val_auc: 0.9860 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00014: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.\n",
      "Epoch 15/60\n",
      "5881/5881 [==============================] - 3s 559us/step - loss: 0.1006 - acc: 0.9597 - auc: 0.9863 - recall: 1.0000 - val_loss: 0.6769 - val_acc: 0.9062 - val_auc: 0.9866 - val_recall: 1.0000\n",
      "Epoch 16/60\n",
      "5881/5881 [==============================] - 3s 564us/step - loss: 0.0985 - acc: 0.9600 - auc: 0.9869 - recall: 1.0000 - val_loss: 0.6736 - val_acc: 0.9048 - val_auc: 0.9871 - val_recall: 1.0000\n",
      "Epoch 17/60\n",
      "5881/5881 [==============================] - 3s 563us/step - loss: 0.0966 - acc: 0.9626 - auc: 0.9873 - recall: 1.0000 - val_loss: 0.6822 - val_acc: 0.9089 - val_auc: 0.9875 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00017: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.\n",
      "Epoch 18/60\n",
      "5881/5881 [==============================] - 3s 561us/step - loss: 0.0957 - acc: 0.9617 - auc: 0.9877 - recall: 1.0000 - val_loss: 0.6753 - val_acc: 0.9089 - val_auc: 0.9878 - val_recall: 1.0000\n",
      "Epoch 19/60\n",
      "5881/5881 [==============================] - 3s 561us/step - loss: 0.0956 - acc: 0.9619 - auc: 0.9880 - recall: 1.0000 - val_loss: 0.6838 - val_acc: 0.9089 - val_auc: 0.9882 - val_recall: 1.0000\n",
      "Epoch 20/60\n",
      "5881/5881 [==============================] - 3s 558us/step - loss: 0.0949 - acc: 0.9609 - auc: 0.9883 - recall: 1.0000 - val_loss: 0.6858 - val_acc: 0.9089 - val_auc: 0.9884 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00020: ReduceLROnPlateau reducing learning rate to 6.25000029685907e-05.\n",
      "Epoch 21/60\n",
      "5881/5881 [==============================] - 3s 566us/step - loss: 0.0928 - acc: 0.9629 - auc: 0.9886 - recall: 1.0000 - val_loss: 0.6777 - val_acc: 0.9075 - val_auc: 0.9887 - val_recall: 1.0000\n",
      "Restoring model weights from the end of the best epoch\n",
      "Epoch 00021: early stopping\n",
      "training time: 90.58042311668396s\n",
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "input_20 (InputLayer)        (None, 128, 9)            0         \n",
      "_________________________________________________________________\n",
      "conv1d_1 (Conv1D)            (None, 119, 100)          9100      \n",
      "_________________________________________________________________\n",
      "conv1d_2 (Conv1D)            (None, 110, 100)          100100    \n",
      "_________________________________________________________________\n",
      "max_pooling1d_1 (MaxPooling1 (None, 36, 100)           0         \n",
      "_________________________________________________________________\n",
      "conv1d_3 (Conv1D)            (None, 27, 160)           160160    \n",
      "_________________________________________________________________\n",
      "max_pooling1d_2 (MaxPooling1 (None, 9, 160)            0         \n",
      "_________________________________________________________________\n",
      "flatten_13 (Flatten)         (None, 1440)              0         \n",
      "_________________________________________________________________\n",
      "dense_134 (Dense)            (None, 20)                28820     \n",
      "_________________________________________________________________\n",
      "dense_135 (Dense)            (None, 6)                 126       \n",
      "=================================================================\n",
      "Total params: 298,306\n",
      "Trainable params: 298,306\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n",
      "Train on 5881 samples, validate on 1471 samples\n",
      "Epoch 1/60\n",
      "5881/5881 [==============================] - 4s 620us/step - loss: 1.1523 - acc: 0.4423 - auc: 0.7283 - recall: 0.9575 - val_loss: 0.8609 - val_acc: 0.6241 - val_auc: 0.8670 - val_recall: 1.0000\n",
      "Epoch 2/60\n",
      "5881/5881 [==============================] - 2s 402us/step - loss: 0.4542 - acc: 0.8397 - auc: 0.9071 - recall: 1.0000 - val_loss: 0.4491 - val_acc: 0.8668 - val_auc: 0.9368 - val_recall: 1.0000\n",
      "Epoch 3/60\n",
      "5881/5881 [==============================] - 2s 399us/step - loss: 0.1928 - acc: 0.9310 - auc: 0.9529 - recall: 1.0000 - val_loss: 0.3029 - val_acc: 0.9109 - val_auc: 0.9641 - val_recall: 1.0000\n",
      "Epoch 4/60\n",
      "5881/5881 [==============================] - 2s 402us/step - loss: 0.1236 - acc: 0.9522 - auc: 0.9710 - recall: 1.0000 - val_loss: 0.3661 - val_acc: 0.9021 - val_auc: 0.9758 - val_recall: 1.0000\n",
      "Epoch 5/60\n",
      "5881/5881 [==============================] - 2s 396us/step - loss: 0.1078 - acc: 0.9570 - auc: 0.9792 - recall: 1.0000 - val_loss: 0.3195 - val_acc: 0.9082 - val_auc: 0.9816 - val_recall: 1.0000\n",
      "Epoch 6/60\n",
      "5881/5881 [==============================] - 2s 398us/step - loss: 0.1037 - acc: 0.9544 - auc: 0.9835 - recall: 1.0000 - val_loss: 0.3255 - val_acc: 0.9164 - val_auc: 0.9850 - val_recall: 1.0000\n",
      "Epoch 7/60\n",
      "5881/5881 [==============================] - 2s 399us/step - loss: 0.1175 - acc: 0.9561 - auc: 0.9861 - recall: 1.0000 - val_loss: 0.3415 - val_acc: 0.9137 - val_auc: 0.9870 - val_recall: 1.0000\n",
      "Epoch 8/60\n",
      "5881/5881 [==============================] - 2s 395us/step - loss: 0.0959 - acc: 0.9590 - auc: 0.9879 - recall: 1.0000 - val_loss: 0.3244 - val_acc: 0.9273 - val_auc: 0.9885 - val_recall: 1.0000\n",
      "Epoch 9/60\n",
      "5881/5881 [==============================] - 2s 397us/step - loss: 0.0887 - acc: 0.9636 - auc: 0.9892 - recall: 1.0000 - val_loss: 0.3255 - val_acc: 0.9300 - val_auc: 0.9896 - val_recall: 1.0000\n",
      "Epoch 10/60\n",
      "5881/5881 [==============================] - 2s 394us/step - loss: 0.0911 - acc: 0.9583 - auc: 0.9900 - recall: 1.0000 - val_loss: 0.3522 - val_acc: 0.9198 - val_auc: 0.9903 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00010: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.\n",
      "Epoch 11/60\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5881/5881 [==============================] - 2s 397us/step - loss: 0.0853 - acc: 0.9609 - auc: 0.9907 - recall: 1.0000 - val_loss: 0.3462 - val_acc: 0.9205 - val_auc: 0.9909 - val_recall: 1.0000\n",
      "Epoch 12/60\n",
      "5881/5881 [==============================] - 2s 398us/step - loss: 0.0866 - acc: 0.9600 - auc: 0.9912 - recall: 1.0000 - val_loss: 0.3406 - val_acc: 0.9279 - val_auc: 0.9914 - val_recall: 1.0000\n",
      "Epoch 13/60\n",
      "5881/5881 [==============================] - 2s 397us/step - loss: 0.0822 - acc: 0.9628 - auc: 0.9916 - recall: 1.0000 - val_loss: 0.3396 - val_acc: 0.9225 - val_auc: 0.9918 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00013: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.\n",
      "Epoch 14/60\n",
      "5881/5881 [==============================] - 2s 396us/step - loss: 0.0812 - acc: 0.9633 - auc: 0.9920 - recall: 1.0000 - val_loss: 0.3580 - val_acc: 0.9205 - val_auc: 0.9921 - val_recall: 1.0000\n",
      "Epoch 15/60\n",
      "5881/5881 [==============================] - 2s 401us/step - loss: 0.0813 - acc: 0.9634 - auc: 0.9922 - recall: 1.0000 - val_loss: 0.3559 - val_acc: 0.9130 - val_auc: 0.9924 - val_recall: 1.0000\n",
      "Epoch 16/60\n",
      "5881/5881 [==============================] - 2s 394us/step - loss: 0.0808 - acc: 0.9629 - auc: 0.9925 - recall: 1.0000 - val_loss: 0.3695 - val_acc: 0.9171 - val_auc: 0.9926 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00016: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.\n",
      "Epoch 17/60\n",
      "5881/5881 [==============================] - 2s 399us/step - loss: 0.0798 - acc: 0.9617 - auc: 0.9927 - recall: 1.0000 - val_loss: 0.3701 - val_acc: 0.9157 - val_auc: 0.9927 - val_recall: 1.0000\n",
      "Restoring model weights from the end of the best epoch\n",
      "Epoch 00017: early stopping\n",
      "training time: 61.17898488044739s\n",
      "Train on 5881 samples, validate on 1471 samples\n",
      "Epoch 1/60\n",
      "5881/5881 [==============================] - 4s 619us/step - loss: 0.9808 - acc: 0.5922 - auc: 0.7492 - recall: 0.9575 - val_loss: 0.8925 - val_acc: 0.6873 - val_auc: 0.9073 - val_recall: 1.0000\n",
      "Epoch 2/60\n",
      "5881/5881 [==============================] - 2s 399us/step - loss: 0.2967 - acc: 0.8881 - auc: 0.9343 - recall: 1.0000 - val_loss: 0.2681 - val_acc: 0.9137 - val_auc: 0.9577 - val_recall: 1.0000\n",
      "Epoch 3/60\n",
      "5881/5881 [==============================] - 2s 396us/step - loss: 0.1415 - acc: 0.9434 - auc: 0.9690 - recall: 1.0000 - val_loss: 0.2790 - val_acc: 0.9082 - val_auc: 0.9761 - val_recall: 1.0000\n",
      "Epoch 4/60\n",
      "5881/5881 [==============================] - 2s 396us/step - loss: 0.1211 - acc: 0.9492 - auc: 0.9803 - recall: 1.0000 - val_loss: 0.2697 - val_acc: 0.9239 - val_auc: 0.9835 - val_recall: 1.0000\n",
      "Epoch 5/60\n",
      "5881/5881 [==============================] - 2s 393us/step - loss: 0.0995 - acc: 0.9589 - auc: 0.9857 - recall: 1.0000 - val_loss: 0.2718 - val_acc: 0.9191 - val_auc: 0.9874 - val_recall: 1.0000\n",
      "Epoch 6/60\n",
      "5881/5881 [==============================] - 2s 397us/step - loss: 0.0903 - acc: 0.9602 - auc: 0.9887 - recall: 1.0000 - val_loss: 0.2529 - val_acc: 0.9245 - val_auc: 0.9897 - val_recall: 1.0000\n",
      "Epoch 7/60\n",
      "5881/5881 [==============================] - 2s 393us/step - loss: 0.0899 - acc: 0.9578 - auc: 0.9906 - recall: 1.0000 - val_loss: 0.2721 - val_acc: 0.9232 - val_auc: 0.9912 - val_recall: 1.0000\n",
      "Epoch 8/60\n",
      "5881/5881 [==============================] - 2s 396us/step - loss: 0.0965 - acc: 0.9549 - auc: 0.9918 - recall: 1.0000 - val_loss: 0.2882 - val_acc: 0.8973 - val_auc: 0.9922 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00008: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.\n",
      "Epoch 9/60\n",
      "5881/5881 [==============================] - 2s 394us/step - loss: 0.0976 - acc: 0.9549 - auc: 0.9927 - recall: 1.0000 - val_loss: 0.2994 - val_acc: 0.9143 - val_auc: 0.9929 - val_recall: 1.0000\n",
      "Epoch 10/60\n",
      "5881/5881 [==============================] - 2s 401us/step - loss: 0.0869 - acc: 0.9583 - auc: 0.9932 - recall: 1.0000 - val_loss: 0.3154 - val_acc: 0.9082 - val_auc: 0.9933 - val_recall: 1.0000\n",
      "Epoch 11/60\n",
      "5881/5881 [==============================] - 2s 393us/step - loss: 0.0890 - acc: 0.9577 - auc: 0.9934 - recall: 1.0000 - val_loss: 0.3032 - val_acc: 0.9130 - val_auc: 0.9936 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00011: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.\n",
      "Epoch 12/60\n",
      "5881/5881 [==============================] - 2s 398us/step - loss: 0.0815 - acc: 0.9617 - auc: 0.9938 - recall: 1.0000 - val_loss: 0.3004 - val_acc: 0.9082 - val_auc: 0.9938 - val_recall: 1.0000\n",
      "Epoch 13/60\n",
      "5881/5881 [==============================] - 2s 397us/step - loss: 0.0784 - acc: 0.9624 - auc: 0.9940 - recall: 1.0000 - val_loss: 0.3089 - val_acc: 0.9130 - val_auc: 0.9940 - val_recall: 1.0000\n",
      "Epoch 14/60\n",
      "5881/5881 [==============================] - 2s 398us/step - loss: 0.0775 - acc: 0.9619 - auc: 0.9942 - recall: 1.0000 - val_loss: 0.3033 - val_acc: 0.9157 - val_auc: 0.9942 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00014: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.\n",
      "Epoch 15/60\n",
      "5881/5881 [==============================] - 2s 399us/step - loss: 0.0761 - acc: 0.9650 - auc: 0.9943 - recall: 1.0000 - val_loss: 0.3115 - val_acc: 0.9109 - val_auc: 0.9944 - val_recall: 1.0000\n",
      "Restoring model weights from the end of the best epoch\n",
      "Epoch 00015: early stopping\n",
      "training time: 56.98405480384827s\n",
      "Train on 5881 samples, validate on 1471 samples\n",
      "Epoch 1/60\n",
      "5881/5881 [==============================] - 4s 641us/step - loss: 0.8919 - acc: 0.6041 - auc: 0.7615 - recall: 0.9575 - val_loss: 0.7076 - val_acc: 0.8137 - val_auc: 0.9243 - val_recall: 1.0000\n",
      "Epoch 2/60\n",
      "5881/5881 [==============================] - 2s 400us/step - loss: 0.2846 - acc: 0.8871 - auc: 0.9506 - recall: 1.0000 - val_loss: 0.4585 - val_acc: 0.9014 - val_auc: 0.9656 - val_recall: 1.0000\n",
      "Epoch 3/60\n",
      "5881/5881 [==============================] - 2s 407us/step - loss: 0.1567 - acc: 0.9390 - auc: 0.9733 - recall: 1.0000 - val_loss: 0.3605 - val_acc: 0.9055 - val_auc: 0.9786 - val_recall: 1.0000\n",
      "Epoch 4/60\n",
      "5881/5881 [==============================] - 2s 401us/step - loss: 0.1097 - acc: 0.9578 - auc: 0.9821 - recall: 1.0000 - val_loss: 0.3179 - val_acc: 0.9184 - val_auc: 0.9846 - val_recall: 1.0000\n",
      "Epoch 5/60\n",
      "5881/5881 [==============================] - 2s 403us/step - loss: 0.1026 - acc: 0.9532 - auc: 0.9864 - recall: 1.0000 - val_loss: 0.3460 - val_acc: 0.9164 - val_auc: 0.9877 - val_recall: 1.0000\n",
      "Epoch 6/60\n",
      "5881/5881 [==============================] - 2s 402us/step - loss: 0.0906 - acc: 0.9597 - auc: 0.9888 - recall: 1.0000 - val_loss: 0.3914 - val_acc: 0.9143 - val_auc: 0.9896 - val_recall: 1.0000\n",
      "Epoch 7/60\n",
      "5881/5881 [==============================] - 2s 399us/step - loss: 0.0885 - acc: 0.9606 - auc: 0.9902 - recall: 1.0000 - val_loss: 0.3570 - val_acc: 0.9293 - val_auc: 0.9906 - val_recall: 1.0000\n",
      "Epoch 8/60\n",
      "5881/5881 [==============================] - 2s 405us/step - loss: 0.0872 - acc: 0.9580 - auc: 0.9911 - recall: 1.0000 - val_loss: 0.3948 - val_acc: 0.9300 - val_auc: 0.9914 - val_recall: 1.0000\n",
      "Epoch 9/60\n",
      "5881/5881 [==============================] - 2s 399us/step - loss: 0.0846 - acc: 0.9585 - auc: 0.9917 - recall: 1.0000 - val_loss: 0.4528 - val_acc: 0.9293 - val_auc: 0.9919 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00009: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.\n",
      "Epoch 10/60\n",
      "5881/5881 [==============================] - 2s 403us/step - loss: 0.0782 - acc: 0.9617 - auc: 0.9922 - recall: 1.0000 - val_loss: 0.4578 - val_acc: 0.9279 - val_auc: 0.9923 - val_recall: 1.0000\n",
      "Epoch 11/60\n",
      "5881/5881 [==============================] - 2s 406us/step - loss: 0.0747 - acc: 0.9621 - auc: 0.9925 - recall: 1.0000 - val_loss: 0.4496 - val_acc: 0.9293 - val_auc: 0.9926 - val_recall: 1.0000\n",
      "Epoch 12/60\n",
      "5881/5881 [==============================] - 2s 400us/step - loss: 0.0714 - acc: 0.9638 - auc: 0.9928 - recall: 1.0000 - val_loss: 0.4820 - val_acc: 0.9191 - val_auc: 0.9929 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00012: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.\n",
      "Epoch 13/60\n",
      "5881/5881 [==============================] - 2s 406us/step - loss: 0.0706 - acc: 0.9636 - auc: 0.9930 - recall: 1.0000 - val_loss: 0.4874 - val_acc: 0.9211 - val_auc: 0.9931 - val_recall: 1.0000\n",
      "Epoch 14/60\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5881/5881 [==============================] - 2s 401us/step - loss: 0.0680 - acc: 0.9646 - auc: 0.9932 - recall: 1.0000 - val_loss: 0.4969 - val_acc: 0.9191 - val_auc: 0.9932 - val_recall: 1.0000\n",
      "Epoch 15/60\n",
      "5881/5881 [==============================] - 2s 401us/step - loss: 0.0682 - acc: 0.9650 - auc: 0.9933 - recall: 1.0000 - val_loss: 0.5054 - val_acc: 0.9137 - val_auc: 0.9934 - val_recall: 1.0000\n",
      "\n",
      "Epoch 00015: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.\n",
      "Epoch 16/60\n",
      "5881/5881 [==============================] - 2s 405us/step - loss: 0.0665 - acc: 0.9662 - auc: 0.9935 - recall: 1.0000 - val_loss: 0.5096 - val_acc: 0.9184 - val_auc: 0.9935 - val_recall: 1.0000\n",
      "Restoring model weights from the end of the best epoch\n",
      "Epoch 00016: early stopping\n",
      "training time: 61.258931398391724s\n"
     ]
    }
   ],
   "source": [
    "#model_types = [ 'LSTM_2','LSTM', 'dense_2','dense', 'ens', 'dense_fc','conv_1d']\n",
    "model_types = [ 'LSTM', 'dense_2','dense', 'ens', 'dense_fc','conv_1d']\n",
    "#model_types = ['conv_1d', 'LSTM_2']\n",
    "trainig_reulsts = {}\n",
    "\n",
    "for model_name in model_types:\n",
    "    \n",
    "    trained_models, trained_models_stats, trained_models_time_taken, trained_models_best_epoch = generate_trained_models(model_name)\n",
    "    stats_best_epoch = pd.DataFrame(trained_models_best_epoch, columns=['epoch']).mean()\n",
    "    stats_time_takes = pd.DataFrame(trained_models_time_taken, columns=['time']).mean()\n",
    "    stats_best_stats = pd.DataFrame(trained_models_stats).mean()\n",
    "\n",
    "    trainig_reulsts[model_name] = {'trained_models': trained_models,\n",
    "                                  'trained_models_stats': trained_models_stats,\n",
    "                                  'trained_models_time_taken': trained_models_time_taken,\n",
    "                                  'trained_models_best_epoch': trained_models_best_epoch,\n",
    "                                  'stats_best_epoch': stats_best_epoch,\n",
    "                                  'stats_time_takes': stats_time_takes,\n",
    "                                  'stats_best_stats': stats_best_stats}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_____\n",
      "model: LSTM \n",
      "\n",
      "mean best epoc: [40.]\n",
      "mean training time: [275.56412427]\n",
      "STATS:\n",
      "acc           0.865216\n",
      "auc           0.959082\n",
      "loss          0.676688\n",
      "lr            0.000014\n",
      "recall        0.984079\n",
      "val_acc       0.852708\n",
      "val_auc       0.959223\n",
      "val_loss      0.689645\n",
      "val_recall    0.983930\n",
      "dtype: float64\n",
      "\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/javascript": [
       "/* Put everything inside the global mpl namespace */\n",
       "window.mpl = {};\n",
       "\n",
       "\n",
       "mpl.get_websocket_type = function() {\n",
       "    if (typeof(WebSocket) !== 'undefined') {\n",
       "        return WebSocket;\n",
       "    } else if (typeof(MozWebSocket) !== 'undefined') {\n",
       "        return MozWebSocket;\n",
       "    } else {\n",
       "        alert('Your browser does not have WebSocket support.' +\n",
       "              'Please try Chrome, Safari or Firefox ≥ 6. ' +\n",
       "              'Firefox 4 and 5 are also supported but you ' +\n",
       "              'have to enable WebSockets in about:config.');\n",
       "    };\n",
       "}\n",
       "\n",
       "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n",
       "    this.id = figure_id;\n",
       "\n",
       "    this.ws = websocket;\n",
       "\n",
       "    this.supports_binary = (this.ws.binaryType != undefined);\n",
       "\n",
       "    if (!this.supports_binary) {\n",
       "        var warnings = document.getElementById(\"mpl-warnings\");\n",
       "        if (warnings) {\n",
       "            warnings.style.display = 'block';\n",
       "            warnings.textContent = (\n",
       "                \"This browser does not support binary websocket messages. \" +\n",
       "                    \"Performance may be slow.\");\n",
       "        }\n",
       "    }\n",
       "\n",
       "    this.imageObj = new Image();\n",
       "\n",
       "    this.context = undefined;\n",
       "    this.message = undefined;\n",
       "    this.canvas = undefined;\n",
       "    this.rubberband_canvas = undefined;\n",
       "    this.rubberband_context = undefined;\n",
       "    this.format_dropdown = undefined;\n",
       "\n",
       "    this.image_mode = 'full';\n",
       "\n",
       "    this.root = $('<div/>');\n",
       "    this._root_extra_style(this.root)\n",
       "    this.root.attr('style', 'display: inline-block');\n",
       "\n",
       "    $(parent_element).append(this.root);\n",
       "\n",
       "    this._init_header(this);\n",
       "    this._init_canvas(this);\n",
       "    this._init_toolbar(this);\n",
       "\n",
       "    var fig = this;\n",
       "\n",
       "    this.waiting = false;\n",
       "\n",
       "    this.ws.onopen =  function () {\n",
       "            fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n",
       "            fig.send_message(\"send_image_mode\", {});\n",
       "            if (mpl.ratio != 1) {\n",
       "                fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n",
       "            }\n",
       "            fig.send_message(\"refresh\", {});\n",
       "        }\n",
       "\n",
       "    this.imageObj.onload = function() {\n",
       "            if (fig.image_mode == 'full') {\n",
       "                // Full images could contain transparency (where diff images\n",
       "                // almost always do), so we need to clear the canvas so that\n",
       "                // there is no ghosting.\n",
       "                fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n",
       "            }\n",
       "            fig.context.drawImage(fig.imageObj, 0, 0);\n",
       "        };\n",
       "\n",
       "    this.imageObj.onunload = function() {\n",
       "        fig.ws.close();\n",
       "    }\n",
       "\n",
       "    this.ws.onmessage = this._make_on_message_function(this);\n",
       "\n",
       "    this.ondownload = ondownload;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_header = function() {\n",
       "    var titlebar = $(\n",
       "        '<div class=\"ui-dialog-titlebar ui-widget-header ui-corner-all ' +\n",
       "        'ui-helper-clearfix\"/>');\n",
       "    var titletext = $(\n",
       "        '<div class=\"ui-dialog-title\" style=\"width: 100%; ' +\n",
       "        'text-align: center; padding: 3px;\"/>');\n",
       "    titlebar.append(titletext)\n",
       "    this.root.append(titlebar);\n",
       "    this.header = titletext[0];\n",
       "}\n",
       "\n",
       "\n",
       "\n",
       "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n",
       "\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n",
       "\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_canvas = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var canvas_div = $('<div/>');\n",
       "\n",
       "    canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n",
       "\n",
       "    function canvas_keyboard_event(event) {\n",
       "        return fig.key_event(event, event['data']);\n",
       "    }\n",
       "\n",
       "    canvas_div.keydown('key_press', canvas_keyboard_event);\n",
       "    canvas_div.keyup('key_release', canvas_keyboard_event);\n",
       "    this.canvas_div = canvas_div\n",
       "    this._canvas_extra_style(canvas_div)\n",
       "    this.root.append(canvas_div);\n",
       "\n",
       "    var canvas = $('<canvas/>');\n",
       "    canvas.addClass('mpl-canvas');\n",
       "    canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n",
       "\n",
       "    this.canvas = canvas[0];\n",
       "    this.context = canvas[0].getContext(\"2d\");\n",
       "\n",
       "    var backingStore = this.context.backingStorePixelRatio ||\n",
       "\tthis.context.webkitBackingStorePixelRatio ||\n",
       "\tthis.context.mozBackingStorePixelRatio ||\n",
       "\tthis.context.msBackingStorePixelRatio ||\n",
       "\tthis.context.oBackingStorePixelRatio ||\n",
       "\tthis.context.backingStorePixelRatio || 1;\n",
       "\n",
       "    mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n",
       "\n",
       "    var rubberband = $('<canvas/>');\n",
       "    rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n",
       "\n",
       "    var pass_mouse_events = true;\n",
       "\n",
       "    canvas_div.resizable({\n",
       "        start: function(event, ui) {\n",
       "            pass_mouse_events = false;\n",
       "        },\n",
       "        resize: function(event, ui) {\n",
       "            fig.request_resize(ui.size.width, ui.size.height);\n",
       "        },\n",
       "        stop: function(event, ui) {\n",
       "            pass_mouse_events = true;\n",
       "            fig.request_resize(ui.size.width, ui.size.height);\n",
       "        },\n",
       "    });\n",
       "\n",
       "    function mouse_event_fn(event) {\n",
       "        if (pass_mouse_events)\n",
       "            return fig.mouse_event(event, event['data']);\n",
       "    }\n",
       "\n",
       "    rubberband.mousedown('button_press', mouse_event_fn);\n",
       "    rubberband.mouseup('button_release', mouse_event_fn);\n",
       "    // Throttle sequential mouse events to 1 every 20ms.\n",
       "    rubberband.mousemove('motion_notify', mouse_event_fn);\n",
       "\n",
       "    rubberband.mouseenter('figure_enter', mouse_event_fn);\n",
       "    rubberband.mouseleave('figure_leave', mouse_event_fn);\n",
       "\n",
       "    canvas_div.on(\"wheel\", function (event) {\n",
       "        event = event.originalEvent;\n",
       "        event['data'] = 'scroll'\n",
       "        if (event.deltaY < 0) {\n",
       "            event.step = 1;\n",
       "        } else {\n",
       "            event.step = -1;\n",
       "        }\n",
       "        mouse_event_fn(event);\n",
       "    });\n",
       "\n",
       "    canvas_div.append(canvas);\n",
       "    canvas_div.append(rubberband);\n",
       "\n",
       "    this.rubberband = rubberband;\n",
       "    this.rubberband_canvas = rubberband[0];\n",
       "    this.rubberband_context = rubberband[0].getContext(\"2d\");\n",
       "    this.rubberband_context.strokeStyle = \"#000000\";\n",
       "\n",
       "    this._resize_canvas = function(width, height) {\n",
       "        // Keep the size of the canvas, canvas container, and rubber band\n",
       "        // canvas in synch.\n",
       "        canvas_div.css('width', width)\n",
       "        canvas_div.css('height', height)\n",
       "\n",
       "        canvas.attr('width', width * mpl.ratio);\n",
       "        canvas.attr('height', height * mpl.ratio);\n",
       "        canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n",
       "\n",
       "        rubberband.attr('width', width);\n",
       "        rubberband.attr('height', height);\n",
       "    }\n",
       "\n",
       "    // Set the figure to an initial 600x600px, this will subsequently be updated\n",
       "    // upon first draw.\n",
       "    this._resize_canvas(600, 600);\n",
       "\n",
       "    // Disable right mouse context menu.\n",
       "    $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n",
       "        return false;\n",
       "    });\n",
       "\n",
       "    function set_focus () {\n",
       "        canvas.focus();\n",
       "        canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    window.setTimeout(set_focus, 100);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_toolbar = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var nav_element = $('<div/>')\n",
       "    nav_element.attr('style', 'width: 100%');\n",
       "    this.root.append(nav_element);\n",
       "\n",
       "    // Define a callback function for later on.\n",
       "    function toolbar_event(event) {\n",
       "        return fig.toolbar_button_onclick(event['data']);\n",
       "    }\n",
       "    function toolbar_mouse_event(event) {\n",
       "        return fig.toolbar_button_onmouseover(event['data']);\n",
       "    }\n",
       "\n",
       "    for(var toolbar_ind in mpl.toolbar_items) {\n",
       "        var name = mpl.toolbar_items[toolbar_ind][0];\n",
       "        var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
       "        var image = mpl.toolbar_items[toolbar_ind][2];\n",
       "        var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
       "\n",
       "        if (!name) {\n",
       "            // put a spacer in here.\n",
       "            continue;\n",
       "        }\n",
       "        var button = $('<button/>');\n",
       "        button.addClass('ui-button ui-widget ui-state-default ui-corner-all ' +\n",
       "                        'ui-button-icon-only');\n",
       "        button.attr('role', 'button');\n",
       "        button.attr('aria-disabled', 'false');\n",
       "        button.click(method_name, toolbar_event);\n",
       "        button.mouseover(tooltip, toolbar_mouse_event);\n",
       "\n",
       "        var icon_img = $('<span/>');\n",
       "        icon_img.addClass('ui-button-icon-primary ui-icon');\n",
       "        icon_img.addClass(image);\n",
       "        icon_img.addClass('ui-corner-all');\n",
       "\n",
       "        var tooltip_span = $('<span/>');\n",
       "        tooltip_span.addClass('ui-button-text');\n",
       "        tooltip_span.html(tooltip);\n",
       "\n",
       "        button.append(icon_img);\n",
       "        button.append(tooltip_span);\n",
       "\n",
       "        nav_element.append(button);\n",
       "    }\n",
       "\n",
       "    var fmt_picker_span = $('<span/>');\n",
       "\n",
       "    var fmt_picker = $('<select/>');\n",
       "    fmt_picker.addClass('mpl-toolbar-option ui-widget ui-widget-content');\n",
       "    fmt_picker_span.append(fmt_picker);\n",
       "    nav_element.append(fmt_picker_span);\n",
       "    this.format_dropdown = fmt_picker[0];\n",
       "\n",
       "    for (var ind in mpl.extensions) {\n",
       "        var fmt = mpl.extensions[ind];\n",
       "        var option = $(\n",
       "            '<option/>', {selected: fmt === mpl.default_extension}).html(fmt);\n",
       "        fmt_picker.append(option)\n",
       "    }\n",
       "\n",
       "    // Add hover states to the ui-buttons\n",
       "    $( \".ui-button\" ).hover(\n",
       "        function() { $(this).addClass(\"ui-state-hover\");},\n",
       "        function() { $(this).removeClass(\"ui-state-hover\");}\n",
       "    );\n",
       "\n",
       "    var status_bar = $('<span class=\"mpl-message\"/>');\n",
       "    nav_element.append(status_bar);\n",
       "    this.message = status_bar[0];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.request_resize = function(x_pixels, y_pixels) {\n",
       "    // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n",
       "    // which will in turn request a refresh of the image.\n",
       "    this.send_message('resize', {'width': x_pixels, 'height': y_pixels});\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.send_message = function(type, properties) {\n",
       "    properties['type'] = type;\n",
       "    properties['figure_id'] = this.id;\n",
       "    this.ws.send(JSON.stringify(properties));\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.send_draw_message = function() {\n",
       "    if (!this.waiting) {\n",
       "        this.waiting = true;\n",
       "        this.ws.send(JSON.stringify({type: \"draw\", figure_id: this.id}));\n",
       "    }\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
       "    var format_dropdown = fig.format_dropdown;\n",
       "    var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n",
       "    fig.ondownload(fig, format);\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype.handle_resize = function(fig, msg) {\n",
       "    var size = msg['size'];\n",
       "    if (size[0] != fig.canvas.width || size[1] != fig.canvas.height) {\n",
       "        fig._resize_canvas(size[0], size[1]);\n",
       "        fig.send_message(\"refresh\", {});\n",
       "    };\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_rubberband = function(fig, msg) {\n",
       "    var x0 = msg['x0'] / mpl.ratio;\n",
       "    var y0 = (fig.canvas.height - msg['y0']) / mpl.ratio;\n",
       "    var x1 = msg['x1'] / mpl.ratio;\n",
       "    var y1 = (fig.canvas.height - msg['y1']) / mpl.ratio;\n",
       "    x0 = Math.floor(x0) + 0.5;\n",
       "    y0 = Math.floor(y0) + 0.5;\n",
       "    x1 = Math.floor(x1) + 0.5;\n",
       "    y1 = Math.floor(y1) + 0.5;\n",
       "    var min_x = Math.min(x0, x1);\n",
       "    var min_y = Math.min(y0, y1);\n",
       "    var width = Math.abs(x1 - x0);\n",
       "    var height = Math.abs(y1 - y0);\n",
       "\n",
       "    fig.rubberband_context.clearRect(\n",
       "        0, 0, fig.canvas.width, fig.canvas.height);\n",
       "\n",
       "    fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_figure_label = function(fig, msg) {\n",
       "    // Updates the figure title.\n",
       "    fig.header.textContent = msg['label'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_cursor = function(fig, msg) {\n",
       "    var cursor = msg['cursor'];\n",
       "    switch(cursor)\n",
       "    {\n",
       "    case 0:\n",
       "        cursor = 'pointer';\n",
       "        break;\n",
       "    case 1:\n",
       "        cursor = 'default';\n",
       "        break;\n",
       "    case 2:\n",
       "        cursor = 'crosshair';\n",
       "        break;\n",
       "    case 3:\n",
       "        cursor = 'move';\n",
       "        break;\n",
       "    }\n",
       "    fig.rubberband_canvas.style.cursor = cursor;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_message = function(fig, msg) {\n",
       "    fig.message.textContent = msg['message'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_draw = function(fig, msg) {\n",
       "    // Request the server to send over a new figure.\n",
       "    fig.send_draw_message();\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_image_mode = function(fig, msg) {\n",
       "    fig.image_mode = msg['mode'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.updated_canvas_event = function() {\n",
       "    // Called whenever the canvas gets updated.\n",
       "    this.send_message(\"ack\", {});\n",
       "}\n",
       "\n",
       "// A function to construct a web socket function for onmessage handling.\n",
       "// Called in the figure constructor.\n",
       "mpl.figure.prototype._make_on_message_function = function(fig) {\n",
       "    return function socket_on_message(evt) {\n",
       "        if (evt.data instanceof Blob) {\n",
       "            /* FIXME: We get \"Resource interpreted as Image but\n",
       "             * transferred with MIME type text/plain:\" errors on\n",
       "             * Chrome.  But how to set the MIME type?  It doesn't seem\n",
       "             * to be part of the websocket stream */\n",
       "            evt.data.type = \"image/png\";\n",
       "\n",
       "            /* Free the memory for the previous frames */\n",
       "            if (fig.imageObj.src) {\n",
       "                (window.URL || window.webkitURL).revokeObjectURL(\n",
       "                    fig.imageObj.src);\n",
       "            }\n",
       "\n",
       "            fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n",
       "                evt.data);\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        }\n",
       "        else if (typeof evt.data === 'string' && evt.data.slice(0, 21) == \"data:image/png;base64\") {\n",
       "            fig.imageObj.src = evt.data;\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        var msg = JSON.parse(evt.data);\n",
       "        var msg_type = msg['type'];\n",
       "\n",
       "        // Call the  \"handle_{type}\" callback, which takes\n",
       "        // the figure and JSON message as its only arguments.\n",
       "        try {\n",
       "            var callback = fig[\"handle_\" + msg_type];\n",
       "        } catch (e) {\n",
       "            console.log(\"No handler for the '\" + msg_type + \"' message type: \", msg);\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        if (callback) {\n",
       "            try {\n",
       "                // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n",
       "                callback(fig, msg);\n",
       "            } catch (e) {\n",
       "                console.log(\"Exception inside the 'handler_\" + msg_type + \"' callback:\", e, e.stack, msg);\n",
       "            }\n",
       "        }\n",
       "    };\n",
       "}\n",
       "\n",
       "// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas\n",
       "mpl.findpos = function(e) {\n",
       "    //this section is from http://www.quirksmode.org/js/events_properties.html\n",
       "    var targ;\n",
       "    if (!e)\n",
       "        e = window.event;\n",
       "    if (e.target)\n",
       "        targ = e.target;\n",
       "    else if (e.srcElement)\n",
       "        targ = e.srcElement;\n",
       "    if (targ.nodeType == 3) // defeat Safari bug\n",
       "        targ = targ.parentNode;\n",
       "\n",
       "    // jQuery normalizes the pageX and pageY\n",
       "    // pageX,Y are the mouse positions relative to the document\n",
       "    // offset() returns the position of the element relative to the document\n",
       "    var x = e.pageX - $(targ).offset().left;\n",
       "    var y = e.pageY - $(targ).offset().top;\n",
       "\n",
       "    return {\"x\": x, \"y\": y};\n",
       "};\n",
       "\n",
       "/*\n",
       " * return a copy of an object with only non-object keys\n",
       " * we need this to avoid circular references\n",
       " * http://stackoverflow.com/a/24161582/3208463\n",
       " */\n",
       "function simpleKeys (original) {\n",
       "  return Object.keys(original).reduce(function (obj, key) {\n",
       "    if (typeof original[key] !== 'object')\n",
       "        obj[key] = original[key]\n",
       "    return obj;\n",
       "  }, {});\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.mouse_event = function(event, name) {\n",
       "    var canvas_pos = mpl.findpos(event)\n",
       "\n",
       "    if (name === 'button_press')\n",
       "    {\n",
       "        this.canvas.focus();\n",
       "        this.canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    var x = canvas_pos.x * mpl.ratio;\n",
       "    var y = canvas_pos.y * mpl.ratio;\n",
       "\n",
       "    this.send_message(name, {x: x, y: y, button: event.button,\n",
       "                             step: event.step,\n",
       "                             guiEvent: simpleKeys(event)});\n",
       "\n",
       "    /* This prevents the web browser from automatically changing to\n",
       "     * the text insertion cursor when the button is pressed.  We want\n",
       "     * to control all of the cursor setting manually through the\n",
       "     * 'cursor' event from matplotlib */\n",
       "    event.preventDefault();\n",
       "    return false;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
       "    // Handle any extra behaviour associated with a key event\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.key_event = function(event, name) {\n",
       "\n",
       "    // Prevent repeat events\n",
       "    if (name == 'key_press')\n",
       "    {\n",
       "        if (event.which === this._key)\n",
       "            return;\n",
       "        else\n",
       "            this._key = event.which;\n",
       "    }\n",
       "    if (name == 'key_release')\n",
       "        this._key = null;\n",
       "\n",
       "    var value = '';\n",
       "    if (event.ctrlKey && event.which != 17)\n",
       "        value += \"ctrl+\";\n",
       "    if (event.altKey && event.which != 18)\n",
       "        value += \"alt+\";\n",
       "    if (event.shiftKey && event.which != 16)\n",
       "        value += \"shift+\";\n",
       "\n",
       "    value += 'k';\n",
       "    value += event.which.toString();\n",
       "\n",
       "    this._key_event_extra(event, name);\n",
       "\n",
       "    this.send_message(name, {key: value,\n",
       "                             guiEvent: simpleKeys(event)});\n",
       "    return false;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.toolbar_button_onclick = function(name) {\n",
       "    if (name == 'download') {\n",
       "        this.handle_save(this, null);\n",
       "    } else {\n",
       "        this.send_message(\"toolbar_button\", {name: name});\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.toolbar_button_onmouseover = function(tooltip) {\n",
       "    this.message.textContent = tooltip;\n",
       "};\n",
       "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Pan axes with left mouse, zoom with right\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n",
       "\n",
       "mpl.extensions = [\"eps\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\"];\n",
       "\n",
       "mpl.default_extension = \"png\";var comm_websocket_adapter = function(comm) {\n",
       "    // Create a \"websocket\"-like object which calls the given IPython comm\n",
       "    // object with the appropriate methods. Currently this is a non binary\n",
       "    // socket, so there is still some room for performance tuning.\n",
       "    var ws = {};\n",
       "\n",
       "    ws.close = function() {\n",
       "        comm.close()\n",
       "    };\n",
       "    ws.send = function(m) {\n",
       "        //console.log('sending', m);\n",
       "        comm.send(m);\n",
       "    };\n",
       "    // Register the callback with on_msg.\n",
       "    comm.on_msg(function(msg) {\n",
       "        //console.log('receiving', msg['content']['data'], msg);\n",
       "        // Pass the mpl event to the overridden (by mpl) onmessage function.\n",
       "        ws.onmessage(msg['content']['data'])\n",
       "    });\n",
       "    return ws;\n",
       "}\n",
       "\n",
       "mpl.mpl_figure_comm = function(comm, msg) {\n",
       "    // This is the function which gets called when the mpl process\n",
       "    // starts-up an IPython Comm through the \"matplotlib\" channel.\n",
       "\n",
       "    var id = msg.content.data.id;\n",
       "    // Get hold of the div created by the display call when the Comm\n",
       "    // socket was opened in Python.\n",
       "    var element = $(\"#\" + id);\n",
       "    var ws_proxy = comm_websocket_adapter(comm)\n",
       "\n",
       "    function ondownload(figure, format) {\n",
       "        window.open(figure.imageObj.src);\n",
       "    }\n",
       "\n",
       "    var fig = new mpl.figure(id, ws_proxy,\n",
       "                           ondownload,\n",
       "                           element.get(0));\n",
       "\n",
       "    // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n",
       "    // web socket which is closed, not our websocket->open comm proxy.\n",
       "    ws_proxy.onopen();\n",
       "\n",
       "    fig.parent_element = element.get(0);\n",
       "    fig.cell_info = mpl.find_output_cell(\"<div id='\" + id + \"'></div>\");\n",
       "    if (!fig.cell_info) {\n",
       "        console.error(\"Failed to find cell for figure\", id, fig);\n",
       "        return;\n",
       "    }\n",
       "\n",
       "    var output_index = fig.cell_info[2]\n",
       "    var cell = fig.cell_info[0];\n",
       "\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_close = function(fig, msg) {\n",
       "    var width = fig.canvas.width/mpl.ratio\n",
       "    fig.root.unbind('remove')\n",
       "\n",
       "    // Update the output cell to use the data from the current canvas.\n",
       "    fig.push_to_output();\n",
       "    var dataURL = fig.canvas.toDataURL();\n",
       "    // Re-enable the keyboard manager in IPython - without this line, in FF,\n",
       "    // the notebook keyboard shortcuts fail.\n",
       "    IPython.keyboard_manager.enable()\n",
       "    $(fig.parent_element).html('<img src=\"' + dataURL + '\" width=\"' + width + '\">');\n",
       "    fig.close_ws(fig, msg);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.close_ws = function(fig, msg){\n",
       "    fig.send_message('closing', msg);\n",
       "    // fig.ws.close()\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.push_to_output = function(remove_interactive) {\n",
       "    // Turn the data on the canvas into data in the output cell.\n",
       "    var width = this.canvas.width/mpl.ratio\n",
       "    var dataURL = this.canvas.toDataURL();\n",
       "    this.cell_info[1]['text/html'] = '<img src=\"' + dataURL + '\" width=\"' + width + '\">';\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.updated_canvas_event = function() {\n",
       "    // Tell IPython that the notebook contents must change.\n",
       "    IPython.notebook.set_dirty(true);\n",
       "    this.send_message(\"ack\", {});\n",
       "    var fig = this;\n",
       "    // Wait a second, then push the new image to the DOM so\n",
       "    // that it is saved nicely (might be nice to debounce this).\n",
       "    setTimeout(function () { fig.push_to_output() }, 1000);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_toolbar = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var nav_element = $('<div/>')\n",
       "    nav_element.attr('style', 'width: 100%');\n",
       "    this.root.append(nav_element);\n",
       "\n",
       "    // Define a callback function for later on.\n",
       "    function toolbar_event(event) {\n",
       "        return fig.toolbar_button_onclick(event['data']);\n",
       "    }\n",
       "    function toolbar_mouse_event(event) {\n",
       "        return fig.toolbar_button_onmouseover(event['data']);\n",
       "    }\n",
       "\n",
       "    for(var toolbar_ind in mpl.toolbar_items){\n",
       "        var name = mpl.toolbar_items[toolbar_ind][0];\n",
       "        var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
       "        var image = mpl.toolbar_items[toolbar_ind][2];\n",
       "        var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
       "\n",
       "        if (!name) { continue; };\n",
       "\n",
       "        var button = $('<button class=\"btn btn-default\" href=\"#\" title=\"' + name + '\"><i class=\"fa ' + image + ' fa-lg\"></i></button>');\n",
       "        button.click(method_name, toolbar_event);\n",
       "        button.mouseover(tooltip, toolbar_mouse_event);\n",
       "        nav_element.append(button);\n",
       "    }\n",
       "\n",
       "    // Add the status bar.\n",
       "    var status_bar = $('<span class=\"mpl-message\" style=\"text-align:right; float: right;\"/>');\n",
       "    nav_element.append(status_bar);\n",
       "    this.message = status_bar[0];\n",
       "\n",
       "    // Add the close button to the window.\n",
       "    var buttongrp = $('<div class=\"btn-group inline pull-right\"></div>');\n",
       "    var button = $('<button class=\"btn btn-mini btn-primary\" href=\"#\" title=\"Stop Interaction\"><i class=\"fa fa-power-off icon-remove icon-large\"></i></button>');\n",
       "    button.click(function (evt) { fig.handle_close(fig, {}); } );\n",
       "    button.mouseover('Stop Interaction', toolbar_mouse_event);\n",
       "    buttongrp.append(button);\n",
       "    var titlebar = this.root.find($('.ui-dialog-titlebar'));\n",
       "    titlebar.prepend(buttongrp);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._root_extra_style = function(el){\n",
       "    var fig = this\n",
       "    el.on(\"remove\", function(){\n",
       "\tfig.close_ws(fig, {});\n",
       "    });\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._canvas_extra_style = function(el){\n",
       "    // this is important to make the div 'focusable\n",
       "    el.attr('tabindex', 0)\n",
       "    // reach out to IPython and tell the keyboard manager to turn it's self\n",
       "    // off when our div gets focus\n",
       "\n",
       "    // location in version 3\n",
       "    if (IPython.notebook.keyboard_manager) {\n",
       "        IPython.notebook.keyboard_manager.register_events(el);\n",
       "    }\n",
       "    else {\n",
       "        // location in version 2\n",
       "        IPython.keyboard_manager.register_events(el);\n",
       "    }\n",
       "\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
       "    var manager = IPython.notebook.keyboard_manager;\n",
       "    if (!manager)\n",
       "        manager = IPython.keyboard_manager;\n",
       "\n",
       "    // Check for shift+enter\n",
       "    if (event.shiftKey && event.which == 13) {\n",
       "        this.canvas_div.blur();\n",
       "        event.shiftKey = false;\n",
       "        // Send a \"J\" for go to next cell\n",
       "        event.which = 74;\n",
       "        event.keyCode = 74;\n",
       "        manager.command_mode();\n",
       "        manager.handle_keydown(event);\n",
       "    }\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
       "    fig.ondownload(fig, null);\n",
       "}\n",
       "\n",
       "\n",
       "mpl.find_output_cell = function(html_output) {\n",
       "    // Return the cell and output element which can be found *uniquely* in the notebook.\n",
       "    // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n",
       "    // IPython event is triggered only after the cells have been serialised, which for\n",
       "    // our purposes (turning an active figure into a static one), is too late.\n",
       "    var cells = IPython.notebook.get_cells();\n",
       "    var ncells = cells.length;\n",
       "    for (var i=0; i<ncells; i++) {\n",
       "        var cell = cells[i];\n",
       "        if (cell.cell_type === 'code'){\n",
       "            for (var j=0; j<cell.output_area.outputs.length; j++) {\n",
       "                var data = cell.output_area.outputs[j];\n",
       "                if (data.data) {\n",
       "                    // IPython >= 3 moved mimebundle to data attribute of output\n",
       "                    data = data.data;\n",
       "                }\n",
       "                if (data['text/html'] == html_output) {\n",
       "                    return [cell, data, j];\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    }\n",
       "}\n",
       "\n",
       "// Register the function which deals with the matplotlib target/channel.\n",
       "// The kernel may be null if the page has been refreshed.\n",
       "if (IPython.notebook.kernel != null) {\n",
       "    IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n",
       "}\n"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<img src=\"\" width=\"400\">"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_____\n",
      "model: dense_2 \n",
      "\n",
      "mean best epoc: [20.33333333]\n",
      "mean training time: [19.49054233]\n",
      "STATS:\n",
      "acc           0.966106\n",
      "auc           0.993378\n",
      "loss          0.077036\n",
      "lr            0.000052\n",
      "recall        1.000000\n",
      "val_acc       0.926807\n",
      "val_auc       0.993440\n",
      "val_loss      0.321176\n",
      "val_recall    1.000000\n",
      "dtype: float64\n",
      "\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/javascript": [
       "/* Put everything inside the global mpl namespace */\n",
       "window.mpl = {};\n",
       "\n",
       "\n",
       "mpl.get_websocket_type = function() {\n",
       "    if (typeof(WebSocket) !== 'undefined') {\n",
       "        return WebSocket;\n",
       "    } else if (typeof(MozWebSocket) !== 'undefined') {\n",
       "        return MozWebSocket;\n",
       "    } else {\n",
       "        alert('Your browser does not have WebSocket support.' +\n",
       "              'Please try Chrome, Safari or Firefox ≥ 6. ' +\n",
       "              'Firefox 4 and 5 are also supported but you ' +\n",
       "              'have to enable WebSockets in about:config.');\n",
       "    };\n",
       "}\n",
       "\n",
       "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n",
       "    this.id = figure_id;\n",
       "\n",
       "    this.ws = websocket;\n",
       "\n",
       "    this.supports_binary = (this.ws.binaryType != undefined);\n",
       "\n",
       "    if (!this.supports_binary) {\n",
       "        var warnings = document.getElementById(\"mpl-warnings\");\n",
       "        if (warnings) {\n",
       "            warnings.style.display = 'block';\n",
       "            warnings.textContent = (\n",
       "                \"This browser does not support binary websocket messages. \" +\n",
       "                    \"Performance may be slow.\");\n",
       "        }\n",
       "    }\n",
       "\n",
       "    this.imageObj = new Image();\n",
       "\n",
       "    this.context = undefined;\n",
       "    this.message = undefined;\n",
       "    this.canvas = undefined;\n",
       "    this.rubberband_canvas = undefined;\n",
       "    this.rubberband_context = undefined;\n",
       "    this.format_dropdown = undefined;\n",
       "\n",
       "    this.image_mode = 'full';\n",
       "\n",
       "    this.root = $('<div/>');\n",
       "    this._root_extra_style(this.root)\n",
       "    this.root.attr('style', 'display: inline-block');\n",
       "\n",
       "    $(parent_element).append(this.root);\n",
       "\n",
       "    this._init_header(this);\n",
       "    this._init_canvas(this);\n",
       "    this._init_toolbar(this);\n",
       "\n",
       "    var fig = this;\n",
       "\n",
       "    this.waiting = false;\n",
       "\n",
       "    this.ws.onopen =  function () {\n",
       "            fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n",
       "            fig.send_message(\"send_image_mode\", {});\n",
       "            if (mpl.ratio != 1) {\n",
       "                fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n",
       "            }\n",
       "            fig.send_message(\"refresh\", {});\n",
       "        }\n",
       "\n",
       "    this.imageObj.onload = function() {\n",
       "            if (fig.image_mode == 'full') {\n",
       "                // Full images could contain transparency (where diff images\n",
       "                // almost always do), so we need to clear the canvas so that\n",
       "                // there is no ghosting.\n",
       "                fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n",
       "            }\n",
       "            fig.context.drawImage(fig.imageObj, 0, 0);\n",
       "        };\n",
       "\n",
       "    this.imageObj.onunload = function() {\n",
       "        fig.ws.close();\n",
       "    }\n",
       "\n",
       "    this.ws.onmessage = this._make_on_message_function(this);\n",
       "\n",
       "    this.ondownload = ondownload;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_header = function() {\n",
       "    var titlebar = $(\n",
       "        '<div class=\"ui-dialog-titlebar ui-widget-header ui-corner-all ' +\n",
       "        'ui-helper-clearfix\"/>');\n",
       "    var titletext = $(\n",
       "        '<div class=\"ui-dialog-title\" style=\"width: 100%; ' +\n",
       "        'text-align: center; padding: 3px;\"/>');\n",
       "    titlebar.append(titletext)\n",
       "    this.root.append(titlebar);\n",
       "    this.header = titletext[0];\n",
       "}\n",
       "\n",
       "\n",
       "\n",
       "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n",
       "\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n",
       "\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_canvas = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var canvas_div = $('<div/>');\n",
       "\n",
       "    canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n",
       "\n",
       "    function canvas_keyboard_event(event) {\n",
       "        return fig.key_event(event, event['data']);\n",
       "    }\n",
       "\n",
       "    canvas_div.keydown('key_press', canvas_keyboard_event);\n",
       "    canvas_div.keyup('key_release', canvas_keyboard_event);\n",
       "    this.canvas_div = canvas_div\n",
       "    this._canvas_extra_style(canvas_div)\n",
       "    this.root.append(canvas_div);\n",
       "\n",
       "    var canvas = $('<canvas/>');\n",
       "    canvas.addClass('mpl-canvas');\n",
       "    canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n",
       "\n",
       "    this.canvas = canvas[0];\n",
       "    this.context = canvas[0].getContext(\"2d\");\n",
       "\n",
       "    var backingStore = this.context.backingStorePixelRatio ||\n",
       "\tthis.context.webkitBackingStorePixelRatio ||\n",
       "\tthis.context.mozBackingStorePixelRatio ||\n",
       "\tthis.context.msBackingStorePixelRatio ||\n",
       "\tthis.context.oBackingStorePixelRatio ||\n",
       "\tthis.context.backingStorePixelRatio || 1;\n",
       "\n",
       "    mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n",
       "\n",
       "    var rubberband = $('<canvas/>');\n",
       "    rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n",
       "\n",
       "    var pass_mouse_events = true;\n",
       "\n",
       "    canvas_div.resizable({\n",
       "        start: function(event, ui) {\n",
       "            pass_mouse_events = false;\n",
       "        },\n",
       "        resize: function(event, ui) {\n",
       "            fig.request_resize(ui.size.width, ui.size.height);\n",
       "        },\n",
       "        stop: function(event, ui) {\n",
       "            pass_mouse_events = true;\n",
       "            fig.request_resize(ui.size.width, ui.size.height);\n",
       "        },\n",
       "    });\n",
       "\n",
       "    function mouse_event_fn(event) {\n",
       "        if (pass_mouse_events)\n",
       "            return fig.mouse_event(event, event['data']);\n",
       "    }\n",
       "\n",
       "    rubberband.mousedown('button_press', mouse_event_fn);\n",
       "    rubberband.mouseup('button_release', mouse_event_fn);\n",
       "    // Throttle sequential mouse events to 1 every 20ms.\n",
       "    rubberband.mousemove('motion_notify', mouse_event_fn);\n",
       "\n",
       "    rubberband.mouseenter('figure_enter', mouse_event_fn);\n",
       "    rubberband.mouseleave('figure_leave', mouse_event_fn);\n",
       "\n",
       "    canvas_div.on(\"wheel\", function (event) {\n",
       "        event = event.originalEvent;\n",
       "        event['data'] = 'scroll'\n",
       "        if (event.deltaY < 0) {\n",
       "            event.step = 1;\n",
       "        } else {\n",
       "            event.step = -1;\n",
       "        }\n",
       "        mouse_event_fn(event);\n",
       "    });\n",
       "\n",
       "    canvas_div.append(canvas);\n",
       "    canvas_div.append(rubberband);\n",
       "\n",
       "    this.rubberband = rubberband;\n",
       "    this.rubberband_canvas = rubberband[0];\n",
       "    this.rubberband_context = rubberband[0].getContext(\"2d\");\n",
       "    this.rubberband_context.strokeStyle = \"#000000\";\n",
       "\n",
       "    this._resize_canvas = function(width, height) {\n",
       "        // Keep the size of the canvas, canvas container, and rubber band\n",
       "        // canvas in synch.\n",
       "        canvas_div.css('width', width)\n",
       "        canvas_div.css('height', height)\n",
       "\n",
       "        canvas.attr('width', width * mpl.ratio);\n",
       "        canvas.attr('height', height * mpl.ratio);\n",
       "        canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n",
       "\n",
       "        rubberband.attr('width', width);\n",
       "        rubberband.attr('height', height);\n",
       "    }\n",
       "\n",
       "    // Set the figure to an initial 600x600px, this will subsequently be updated\n",
       "    // upon first draw.\n",
       "    this._resize_canvas(600, 600);\n",
       "\n",
       "    // Disable right mouse context menu.\n",
       "    $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n",
       "        return false;\n",
       "    });\n",
       "\n",
       "    function set_focus () {\n",
       "        canvas.focus();\n",
       "        canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    window.setTimeout(set_focus, 100);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_toolbar = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var nav_element = $('<div/>')\n",
       "    nav_element.attr('style', 'width: 100%');\n",
       "    this.root.append(nav_element);\n",
       "\n",
       "    // Define a callback function for later on.\n",
       "    function toolbar_event(event) {\n",
       "        return fig.toolbar_button_onclick(event['data']);\n",
       "    }\n",
       "    function toolbar_mouse_event(event) {\n",
       "        return fig.toolbar_button_onmouseover(event['data']);\n",
       "    }\n",
       "\n",
       "    for(var toolbar_ind in mpl.toolbar_items) {\n",
       "        var name = mpl.toolbar_items[toolbar_ind][0];\n",
       "        var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
       "        var image = mpl.toolbar_items[toolbar_ind][2];\n",
       "        var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
       "\n",
       "        if (!name) {\n",
       "            // put a spacer in here.\n",
       "            continue;\n",
       "        }\n",
       "        var button = $('<button/>');\n",
       "        button.addClass('ui-button ui-widget ui-state-default ui-corner-all ' +\n",
       "                        'ui-button-icon-only');\n",
       "        button.attr('role', 'button');\n",
       "        button.attr('aria-disabled', 'false');\n",
       "        button.click(method_name, toolbar_event);\n",
       "        button.mouseover(tooltip, toolbar_mouse_event);\n",
       "\n",
       "        var icon_img = $('<span/>');\n",
       "        icon_img.addClass('ui-button-icon-primary ui-icon');\n",
       "        icon_img.addClass(image);\n",
       "        icon_img.addClass('ui-corner-all');\n",
       "\n",
       "        var tooltip_span = $('<span/>');\n",
       "        tooltip_span.addClass('ui-button-text');\n",
       "        tooltip_span.html(tooltip);\n",
       "\n",
       "        button.append(icon_img);\n",
       "        button.append(tooltip_span);\n",
       "\n",
       "        nav_element.append(button);\n",
       "    }\n",
       "\n",
       "    var fmt_picker_span = $('<span/>');\n",
       "\n",
       "    var fmt_picker = $('<select/>');\n",
       "    fmt_picker.addClass('mpl-toolbar-option ui-widget ui-widget-content');\n",
       "    fmt_picker_span.append(fmt_picker);\n",
       "    nav_element.append(fmt_picker_span);\n",
       "    this.format_dropdown = fmt_picker[0];\n",
       "\n",
       "    for (var ind in mpl.extensions) {\n",
       "        var fmt = mpl.extensions[ind];\n",
       "        var option = $(\n",
       "            '<option/>', {selected: fmt === mpl.default_extension}).html(fmt);\n",
       "        fmt_picker.append(option)\n",
       "    }\n",
       "\n",
       "    // Add hover states to the ui-buttons\n",
       "    $( \".ui-button\" ).hover(\n",
       "        function() { $(this).addClass(\"ui-state-hover\");},\n",
       "        function() { $(this).removeClass(\"ui-state-hover\");}\n",
       "    );\n",
       "\n",
       "    var status_bar = $('<span class=\"mpl-message\"/>');\n",
       "    nav_element.append(status_bar);\n",
       "    this.message = status_bar[0];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.request_resize = function(x_pixels, y_pixels) {\n",
       "    // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n",
       "    // which will in turn request a refresh of the image.\n",
       "    this.send_message('resize', {'width': x_pixels, 'height': y_pixels});\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.send_message = function(type, properties) {\n",
       "    properties['type'] = type;\n",
       "    properties['figure_id'] = this.id;\n",
       "    this.ws.send(JSON.stringify(properties));\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.send_draw_message = function() {\n",
       "    if (!this.waiting) {\n",
       "        this.waiting = true;\n",
       "        this.ws.send(JSON.stringify({type: \"draw\", figure_id: this.id}));\n",
       "    }\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
       "    var format_dropdown = fig.format_dropdown;\n",
       "    var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n",
       "    fig.ondownload(fig, format);\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype.handle_resize = function(fig, msg) {\n",
       "    var size = msg['size'];\n",
       "    if (size[0] != fig.canvas.width || size[1] != fig.canvas.height) {\n",
       "        fig._resize_canvas(size[0], size[1]);\n",
       "        fig.send_message(\"refresh\", {});\n",
       "    };\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_rubberband = function(fig, msg) {\n",
       "    var x0 = msg['x0'] / mpl.ratio;\n",
       "    var y0 = (fig.canvas.height - msg['y0']) / mpl.ratio;\n",
       "    var x1 = msg['x1'] / mpl.ratio;\n",
       "    var y1 = (fig.canvas.height - msg['y1']) / mpl.ratio;\n",
       "    x0 = Math.floor(x0) + 0.5;\n",
       "    y0 = Math.floor(y0) + 0.5;\n",
       "    x1 = Math.floor(x1) + 0.5;\n",
       "    y1 = Math.floor(y1) + 0.5;\n",
       "    var min_x = Math.min(x0, x1);\n",
       "    var min_y = Math.min(y0, y1);\n",
       "    var width = Math.abs(x1 - x0);\n",
       "    var height = Math.abs(y1 - y0);\n",
       "\n",
       "    fig.rubberband_context.clearRect(\n",
       "        0, 0, fig.canvas.width, fig.canvas.height);\n",
       "\n",
       "    fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_figure_label = function(fig, msg) {\n",
       "    // Updates the figure title.\n",
       "    fig.header.textContent = msg['label'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_cursor = function(fig, msg) {\n",
       "    var cursor = msg['cursor'];\n",
       "    switch(cursor)\n",
       "    {\n",
       "    case 0:\n",
       "        cursor = 'pointer';\n",
       "        break;\n",
       "    case 1:\n",
       "        cursor = 'default';\n",
       "        break;\n",
       "    case 2:\n",
       "        cursor = 'crosshair';\n",
       "        break;\n",
       "    case 3:\n",
       "        cursor = 'move';\n",
       "        break;\n",
       "    }\n",
       "    fig.rubberband_canvas.style.cursor = cursor;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_message = function(fig, msg) {\n",
       "    fig.message.textContent = msg['message'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_draw = function(fig, msg) {\n",
       "    // Request the server to send over a new figure.\n",
       "    fig.send_draw_message();\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_image_mode = function(fig, msg) {\n",
       "    fig.image_mode = msg['mode'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.updated_canvas_event = function() {\n",
       "    // Called whenever the canvas gets updated.\n",
       "    this.send_message(\"ack\", {});\n",
       "}\n",
       "\n",
       "// A function to construct a web socket function for onmessage handling.\n",
       "// Called in the figure constructor.\n",
       "mpl.figure.prototype._make_on_message_function = function(fig) {\n",
       "    return function socket_on_message(evt) {\n",
       "        if (evt.data instanceof Blob) {\n",
       "            /* FIXME: We get \"Resource interpreted as Image but\n",
       "             * transferred with MIME type text/plain:\" errors on\n",
       "             * Chrome.  But how to set the MIME type?  It doesn't seem\n",
       "             * to be part of the websocket stream */\n",
       "            evt.data.type = \"image/png\";\n",
       "\n",
       "            /* Free the memory for the previous frames */\n",
       "            if (fig.imageObj.src) {\n",
       "                (window.URL || window.webkitURL).revokeObjectURL(\n",
       "                    fig.imageObj.src);\n",
       "            }\n",
       "\n",
       "            fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n",
       "                evt.data);\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        }\n",
       "        else if (typeof evt.data === 'string' && evt.data.slice(0, 21) == \"data:image/png;base64\") {\n",
       "            fig.imageObj.src = evt.data;\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        var msg = JSON.parse(evt.data);\n",
       "        var msg_type = msg['type'];\n",
       "\n",
       "        // Call the  \"handle_{type}\" callback, which takes\n",
       "        // the figure and JSON message as its only arguments.\n",
       "        try {\n",
       "            var callback = fig[\"handle_\" + msg_type];\n",
       "        } catch (e) {\n",
       "            console.log(\"No handler for the '\" + msg_type + \"' message type: \", msg);\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        if (callback) {\n",
       "            try {\n",
       "                // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n",
       "                callback(fig, msg);\n",
       "            } catch (e) {\n",
       "                console.log(\"Exception inside the 'handler_\" + msg_type + \"' callback:\", e, e.stack, msg);\n",
       "            }\n",
       "        }\n",
       "    };\n",
       "}\n",
       "\n",
       "// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas\n",
       "mpl.findpos = function(e) {\n",
       "    //this section is from http://www.quirksmode.org/js/events_properties.html\n",
       "    var targ;\n",
       "    if (!e)\n",
       "        e = window.event;\n",
       "    if (e.target)\n",
       "        targ = e.target;\n",
       "    else if (e.srcElement)\n",
       "        targ = e.srcElement;\n",
       "    if (targ.nodeType == 3) // defeat Safari bug\n",
       "        targ = targ.parentNode;\n",
       "\n",
       "    // jQuery normalizes the pageX and pageY\n",
       "    // pageX,Y are the mouse positions relative to the document\n",
       "    // offset() returns the position of the element relative to the document\n",
       "    var x = e.pageX - $(targ).offset().left;\n",
       "    var y = e.pageY - $(targ).offset().top;\n",
       "\n",
       "    return {\"x\": x, \"y\": y};\n",
       "};\n",
       "\n",
       "/*\n",
       " * return a copy of an object with only non-object keys\n",
       " * we need this to avoid circular references\n",
       " * http://stackoverflow.com/a/24161582/3208463\n",
       " */\n",
       "function simpleKeys (original) {\n",
       "  return Object.keys(original).reduce(function (obj, key) {\n",
       "    if (typeof original[key] !== 'object')\n",
       "        obj[key] = original[key]\n",
       "    return obj;\n",
       "  }, {});\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.mouse_event = function(event, name) {\n",
       "    var canvas_pos = mpl.findpos(event)\n",
       "\n",
       "    if (name === 'button_press')\n",
       "    {\n",
       "        this.canvas.focus();\n",
       "        this.canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    var x = canvas_pos.x * mpl.ratio;\n",
       "    var y = canvas_pos.y * mpl.ratio;\n",
       "\n",
       "    this.send_message(name, {x: x, y: y, button: event.button,\n",
       "                             step: event.step,\n",
       "                             guiEvent: simpleKeys(event)});\n",
       "\n",
       "    /* This prevents the web browser from automatically changing to\n",
       "     * the text insertion cursor when the button is pressed.  We want\n",
       "     * to control all of the cursor setting manually through the\n",
       "     * 'cursor' event from matplotlib */\n",
       "    event.preventDefault();\n",
       "    return false;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
       "    // Handle any extra behaviour associated with a key event\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.key_event = function(event, name) {\n",
       "\n",
       "    // Prevent repeat events\n",
       "    if (name == 'key_press')\n",
       "    {\n",
       "        if (event.which === this._key)\n",
       "            return;\n",
       "        else\n",
       "            this._key = event.which;\n",
       "    }\n",
       "    if (name == 'key_release')\n",
       "        this._key = null;\n",
       "\n",
       "    var value = '';\n",
       "    if (event.ctrlKey && event.which != 17)\n",
       "        value += \"ctrl+\";\n",
       "    if (event.altKey && event.which != 18)\n",
       "        value += \"alt+\";\n",
       "    if (event.shiftKey && event.which != 16)\n",
       "        value += \"shift+\";\n",
       "\n",
       "    value += 'k';\n",
       "    value += event.which.toString();\n",
       "\n",
       "    this._key_event_extra(event, name);\n",
       "\n",
       "    this.send_message(name, {key: value,\n",
       "                             guiEvent: simpleKeys(event)});\n",
       "    return false;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.toolbar_button_onclick = function(name) {\n",
       "    if (name == 'download') {\n",
       "        this.handle_save(this, null);\n",
       "    } else {\n",
       "        this.send_message(\"toolbar_button\", {name: name});\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.toolbar_button_onmouseover = function(tooltip) {\n",
       "    this.message.textContent = tooltip;\n",
       "};\n",
       "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Pan axes with left mouse, zoom with right\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n",
       "\n",
       "mpl.extensions = [\"eps\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\"];\n",
       "\n",
       "mpl.default_extension = \"png\";var comm_websocket_adapter = function(comm) {\n",
       "    // Create a \"websocket\"-like object which calls the given IPython comm\n",
       "    // object with the appropriate methods. Currently this is a non binary\n",
       "    // socket, so there is still some room for performance tuning.\n",
       "    var ws = {};\n",
       "\n",
       "    ws.close = function() {\n",
       "        comm.close()\n",
       "    };\n",
       "    ws.send = function(m) {\n",
       "        //console.log('sending', m);\n",
       "        comm.send(m);\n",
       "    };\n",
       "    // Register the callback with on_msg.\n",
       "    comm.on_msg(function(msg) {\n",
       "        //console.log('receiving', msg['content']['data'], msg);\n",
       "        // Pass the mpl event to the overridden (by mpl) onmessage function.\n",
       "        ws.onmessage(msg['content']['data'])\n",
       "    });\n",
       "    return ws;\n",
       "}\n",
       "\n",
       "mpl.mpl_figure_comm = function(comm, msg) {\n",
       "    // This is the function which gets called when the mpl process\n",
       "    // starts-up an IPython Comm through the \"matplotlib\" channel.\n",
       "\n",
       "    var id = msg.content.data.id;\n",
       "    // Get hold of the div created by the display call when the Comm\n",
       "    // socket was opened in Python.\n",
       "    var element = $(\"#\" + id);\n",
       "    var ws_proxy = comm_websocket_adapter(comm)\n",
       "\n",
       "    function ondownload(figure, format) {\n",
       "        window.open(figure.imageObj.src);\n",
       "    }\n",
       "\n",
       "    var fig = new mpl.figure(id, ws_proxy,\n",
       "                           ondownload,\n",
       "                           element.get(0));\n",
       "\n",
       "    // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n",
       "    // web socket which is closed, not our websocket->open comm proxy.\n",
       "    ws_proxy.onopen();\n",
       "\n",
       "    fig.parent_element = element.get(0);\n",
       "    fig.cell_info = mpl.find_output_cell(\"<div id='\" + id + \"'></div>\");\n",
       "    if (!fig.cell_info) {\n",
       "        console.error(\"Failed to find cell for figure\", id, fig);\n",
       "        return;\n",
       "    }\n",
       "\n",
       "    var output_index = fig.cell_info[2]\n",
       "    var cell = fig.cell_info[0];\n",
       "\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_close = function(fig, msg) {\n",
       "    var width = fig.canvas.width/mpl.ratio\n",
       "    fig.root.unbind('remove')\n",
       "\n",
       "    // Update the output cell to use the data from the current canvas.\n",
       "    fig.push_to_output();\n",
       "    var dataURL = fig.canvas.toDataURL();\n",
       "    // Re-enable the keyboard manager in IPython - without this line, in FF,\n",
       "    // the notebook keyboard shortcuts fail.\n",
       "    IPython.keyboard_manager.enable()\n",
       "    $(fig.parent_element).html('<img src=\"' + dataURL + '\" width=\"' + width + '\">');\n",
       "    fig.close_ws(fig, msg);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.close_ws = function(fig, msg){\n",
       "    fig.send_message('closing', msg);\n",
       "    // fig.ws.close()\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.push_to_output = function(remove_interactive) {\n",
       "    // Turn the data on the canvas into data in the output cell.\n",
       "    var width = this.canvas.width/mpl.ratio\n",
       "    var dataURL = this.canvas.toDataURL();\n",
       "    this.cell_info[1]['text/html'] = '<img src=\"' + dataURL + '\" width=\"' + width + '\">';\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.updated_canvas_event = function() {\n",
       "    // Tell IPython that the notebook contents must change.\n",
       "    IPython.notebook.set_dirty(true);\n",
       "    this.send_message(\"ack\", {});\n",
       "    var fig = this;\n",
       "    // Wait a second, then push the new image to the DOM so\n",
       "    // that it is saved nicely (might be nice to debounce this).\n",
       "    setTimeout(function () { fig.push_to_output() }, 1000);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_toolbar = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var nav_element = $('<div/>')\n",
       "    nav_element.attr('style', 'width: 100%');\n",
       "    this.root.append(nav_element);\n",
       "\n",
       "    // Define a callback function for later on.\n",
       "    function toolbar_event(event) {\n",
       "        return fig.toolbar_button_onclick(event['data']);\n",
       "    }\n",
       "    function toolbar_mouse_event(event) {\n",
       "        return fig.toolbar_button_onmouseover(event['data']);\n",
       "    }\n",
       "\n",
       "    for(var toolbar_ind in mpl.toolbar_items){\n",
       "        var name = mpl.toolbar_items[toolbar_ind][0];\n",
       "        var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
       "        var image = mpl.toolbar_items[toolbar_ind][2];\n",
       "        var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
       "\n",
       "        if (!name) { continue; };\n",
       "\n",
       "        var button = $('<button class=\"btn btn-default\" href=\"#\" title=\"' + name + '\"><i class=\"fa ' + image + ' fa-lg\"></i></button>');\n",
       "        button.click(method_name, toolbar_event);\n",
       "        button.mouseover(tooltip, toolbar_mouse_event);\n",
       "        nav_element.append(button);\n",
       "    }\n",
       "\n",
       "    // Add the status bar.\n",
       "    var status_bar = $('<span class=\"mpl-message\" style=\"text-align:right; float: right;\"/>');\n",
       "    nav_element.append(status_bar);\n",
       "    this.message = status_bar[0];\n",
       "\n",
       "    // Add the close button to the window.\n",
       "    var buttongrp = $('<div class=\"btn-group inline pull-right\"></div>');\n",
       "    var button = $('<button class=\"btn btn-mini btn-primary\" href=\"#\" title=\"Stop Interaction\"><i class=\"fa fa-power-off icon-remove icon-large\"></i></button>');\n",
       "    button.click(function (evt) { fig.handle_close(fig, {}); } );\n",
       "    button.mouseover('Stop Interaction', toolbar_mouse_event);\n",
       "    buttongrp.append(button);\n",
       "    var titlebar = this.root.find($('.ui-dialog-titlebar'));\n",
       "    titlebar.prepend(buttongrp);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._root_extra_style = function(el){\n",
       "    var fig = this\n",
       "    el.on(\"remove\", function(){\n",
       "\tfig.close_ws(fig, {});\n",
       "    });\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._canvas_extra_style = function(el){\n",
       "    // this is important to make the div 'focusable\n",
       "    el.attr('tabindex', 0)\n",
       "    // reach out to IPython and tell the keyboard manager to turn it's self\n",
       "    // off when our div gets focus\n",
       "\n",
       "    // location in version 3\n",
       "    if (IPython.notebook.keyboard_manager) {\n",
       "        IPython.notebook.keyboard_manager.register_events(el);\n",
       "    }\n",
       "    else {\n",
       "        // location in version 2\n",
       "        IPython.keyboard_manager.register_events(el);\n",
       "    }\n",
       "\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
       "    var manager = IPython.notebook.keyboard_manager;\n",
       "    if (!manager)\n",
       "        manager = IPython.keyboard_manager;\n",
       "\n",
       "    // Check for shift+enter\n",
       "    if (event.shiftKey && event.which == 13) {\n",
       "        this.canvas_div.blur();\n",
       "        event.shiftKey = false;\n",
       "        // Send a \"J\" for go to next cell\n",
       "        event.which = 74;\n",
       "        event.keyCode = 74;\n",
       "        manager.command_mode();\n",
       "        manager.handle_keydown(event);\n",
       "    }\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
       "    fig.ondownload(fig, null);\n",
       "}\n",
       "\n",
       "\n",
       "mpl.find_output_cell = function(html_output) {\n",
       "    // Return the cell and output element which can be found *uniquely* in the notebook.\n",
       "    // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n",
       "    // IPython event is triggered only after the cells have been serialised, which for\n",
       "    // our purposes (turning an active figure into a static one), is too late.\n",
       "    var cells = IPython.notebook.get_cells();\n",
       "    var ncells = cells.length;\n",
       "    for (var i=0; i<ncells; i++) {\n",
       "        var cell = cells[i];\n",
       "        if (cell.cell_type === 'code'){\n",
       "            for (var j=0; j<cell.output_area.outputs.length; j++) {\n",
       "                var data = cell.output_area.outputs[j];\n",
       "                if (data.data) {\n",
       "                    // IPython >= 3 moved mimebundle to data attribute of output\n",
       "                    data = data.data;\n",
       "                }\n",
       "                if (data['text/html'] == html_output) {\n",
       "                    return [cell, data, j];\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    }\n",
       "}\n",
       "\n",
       "// Register the function which deals with the matplotlib target/channel.\n",
       "// The kernel may be null if the page has been refreshed.\n",
       "if (IPython.notebook.kernel != null) {\n",
       "    IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n",
       "}\n"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<img src=\"\" width=\"400\">"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_____\n",
      "model: dense \n",
      "\n",
      "mean best epoc: [20.66666667]\n",
      "mean training time: [21.13987708]\n",
      "STATS:\n",
      "acc           0.957207\n",
      "auc           0.991995\n",
      "loss          0.106021\n",
      "lr            0.000052\n",
      "recall        1.000000\n",
      "val_acc       0.915250\n",
      "val_auc       0.992079\n",
      "val_loss      0.321964\n",
      "val_recall    1.000000\n",
      "dtype: float64\n",
      "\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/javascript": [
       "/* Put everything inside the global mpl namespace */\n",
       "window.mpl = {};\n",
       "\n",
       "\n",
       "mpl.get_websocket_type = function() {\n",
       "    if (typeof(WebSocket) !== 'undefined') {\n",
       "        return WebSocket;\n",
       "    } else if (typeof(MozWebSocket) !== 'undefined') {\n",
       "        return MozWebSocket;\n",
       "    } else {\n",
       "        alert('Your browser does not have WebSocket support.' +\n",
       "              'Please try Chrome, Safari or Firefox ≥ 6. ' +\n",
       "              'Firefox 4 and 5 are also supported but you ' +\n",
       "              'have to enable WebSockets in about:config.');\n",
       "    };\n",
       "}\n",
       "\n",
       "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n",
       "    this.id = figure_id;\n",
       "\n",
       "    this.ws = websocket;\n",
       "\n",
       "    this.supports_binary = (this.ws.binaryType != undefined);\n",
       "\n",
       "    if (!this.supports_binary) {\n",
       "        var warnings = document.getElementById(\"mpl-warnings\");\n",
       "        if (warnings) {\n",
       "            warnings.style.display = 'block';\n",
       "            warnings.textContent = (\n",
       "                \"This browser does not support binary websocket messages. \" +\n",
       "                    \"Performance may be slow.\");\n",
       "        }\n",
       "    }\n",
       "\n",
       "    this.imageObj = new Image();\n",
       "\n",
       "    this.context = undefined;\n",
       "    this.message = undefined;\n",
       "    this.canvas = undefined;\n",
       "    this.rubberband_canvas = undefined;\n",
       "    this.rubberband_context = undefined;\n",
       "    this.format_dropdown = undefined;\n",
       "\n",
       "    this.image_mode = 'full';\n",
       "\n",
       "    this.root = $('<div/>');\n",
       "    this._root_extra_style(this.root)\n",
       "    this.root.attr('style', 'display: inline-block');\n",
       "\n",
       "    $(parent_element).append(this.root);\n",
       "\n",
       "    this._init_header(this);\n",
       "    this._init_canvas(this);\n",
       "    this._init_toolbar(this);\n",
       "\n",
       "    var fig = this;\n",
       "\n",
       "    this.waiting = false;\n",
       "\n",
       "    this.ws.onopen =  function () {\n",
       "            fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n",
       "            fig.send_message(\"send_image_mode\", {});\n",
       "            if (mpl.ratio != 1) {\n",
       "                fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n",
       "            }\n",
       "            fig.send_message(\"refresh\", {});\n",
       "        }\n",
       "\n",
       "    this.imageObj.onload = function() {\n",
       "            if (fig.image_mode == 'full') {\n",
       "                // Full images could contain transparency (where diff images\n",
       "                // almost always do), so we need to clear the canvas so that\n",
       "                // there is no ghosting.\n",
       "                fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n",
       "            }\n",
       "            fig.context.drawImage(fig.imageObj, 0, 0);\n",
       "        };\n",
       "\n",
       "    this.imageObj.onunload = function() {\n",
       "        fig.ws.close();\n",
       "    }\n",
       "\n",
       "    this.ws.onmessage = this._make_on_message_function(this);\n",
       "\n",
       "    this.ondownload = ondownload;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_header = function() {\n",
       "    var titlebar = $(\n",
       "        '<div class=\"ui-dialog-titlebar ui-widget-header ui-corner-all ' +\n",
       "        'ui-helper-clearfix\"/>');\n",
       "    var titletext = $(\n",
       "        '<div class=\"ui-dialog-title\" style=\"width: 100%; ' +\n",
       "        'text-align: center; padding: 3px;\"/>');\n",
       "    titlebar.append(titletext)\n",
       "    this.root.append(titlebar);\n",
       "    this.header = titletext[0];\n",
       "}\n",
       "\n",
       "\n",
       "\n",
       "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n",
       "\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n",
       "\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_canvas = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var canvas_div = $('<div/>');\n",
       "\n",
       "    canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n",
       "\n",
       "    function canvas_keyboard_event(event) {\n",
       "        return fig.key_event(event, event['data']);\n",
       "    }\n",
       "\n",
       "    canvas_div.keydown('key_press', canvas_keyboard_event);\n",
       "    canvas_div.keyup('key_release', canvas_keyboard_event);\n",
       "    this.canvas_div = canvas_div\n",
       "    this._canvas_extra_style(canvas_div)\n",
       "    this.root.append(canvas_div);\n",
       "\n",
       "    var canvas = $('<canvas/>');\n",
       "    canvas.addClass('mpl-canvas');\n",
       "    canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n",
       "\n",
       "    this.canvas = canvas[0];\n",
       "    this.context = canvas[0].getContext(\"2d\");\n",
       "\n",
       "    var backingStore = this.context.backingStorePixelRatio ||\n",
       "\tthis.context.webkitBackingStorePixelRatio ||\n",
       "\tthis.context.mozBackingStorePixelRatio ||\n",
       "\tthis.context.msBackingStorePixelRatio ||\n",
       "\tthis.context.oBackingStorePixelRatio ||\n",
       "\tthis.context.backingStorePixelRatio || 1;\n",
       "\n",
       "    mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n",
       "\n",
       "    var rubberband = $('<canvas/>');\n",
       "    rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n",
       "\n",
       "    var pass_mouse_events = true;\n",
       "\n",
       "    canvas_div.resizable({\n",
       "        start: function(event, ui) {\n",
       "            pass_mouse_events = false;\n",
       "        },\n",
       "        resize: function(event, ui) {\n",
       "            fig.request_resize(ui.size.width, ui.size.height);\n",
       "        },\n",
       "        stop: function(event, ui) {\n",
       "            pass_mouse_events = true;\n",
       "            fig.request_resize(ui.size.width, ui.size.height);\n",
       "        },\n",
       "    });\n",
       "\n",
       "    function mouse_event_fn(event) {\n",
       "        if (pass_mouse_events)\n",
       "            return fig.mouse_event(event, event['data']);\n",
       "    }\n",
       "\n",
       "    rubberband.mousedown('button_press', mouse_event_fn);\n",
       "    rubberband.mouseup('button_release', mouse_event_fn);\n",
       "    // Throttle sequential mouse events to 1 every 20ms.\n",
       "    rubberband.mousemove('motion_notify', mouse_event_fn);\n",
       "\n",
       "    rubberband.mouseenter('figure_enter', mouse_event_fn);\n",
       "    rubberband.mouseleave('figure_leave', mouse_event_fn);\n",
       "\n",
       "    canvas_div.on(\"wheel\", function (event) {\n",
       "        event = event.originalEvent;\n",
       "        event['data'] = 'scroll'\n",
       "        if (event.deltaY < 0) {\n",
       "            event.step = 1;\n",
       "        } else {\n",
       "            event.step = -1;\n",
       "        }\n",
       "        mouse_event_fn(event);\n",
       "    });\n",
       "\n",
       "    canvas_div.append(canvas);\n",
       "    canvas_div.append(rubberband);\n",
       "\n",
       "    this.rubberband = rubberband;\n",
       "    this.rubberband_canvas = rubberband[0];\n",
       "    this.rubberband_context = rubberband[0].getContext(\"2d\");\n",
       "    this.rubberband_context.strokeStyle = \"#000000\";\n",
       "\n",
       "    this._resize_canvas = function(width, height) {\n",
       "        // Keep the size of the canvas, canvas container, and rubber band\n",
       "        // canvas in synch.\n",
       "        canvas_div.css('width', width)\n",
       "        canvas_div.css('height', height)\n",
       "\n",
       "        canvas.attr('width', width * mpl.ratio);\n",
       "        canvas.attr('height', height * mpl.ratio);\n",
       "        canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n",
       "\n",
       "        rubberband.attr('width', width);\n",
       "        rubberband.attr('height', height);\n",
       "    }\n",
       "\n",
       "    // Set the figure to an initial 600x600px, this will subsequently be updated\n",
       "    // upon first draw.\n",
       "    this._resize_canvas(600, 600);\n",
       "\n",
       "    // Disable right mouse context menu.\n",
       "    $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n",
       "        return false;\n",
       "    });\n",
       "\n",
       "    function set_focus () {\n",
       "        canvas.focus();\n",
       "        canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    window.setTimeout(set_focus, 100);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_toolbar = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var nav_element = $('<div/>')\n",
       "    nav_element.attr('style', 'width: 100%');\n",
       "    this.root.append(nav_element);\n",
       "\n",
       "    // Define a callback function for later on.\n",
       "    function toolbar_event(event) {\n",
       "        return fig.toolbar_button_onclick(event['data']);\n",
       "    }\n",
       "    function toolbar_mouse_event(event) {\n",
       "        return fig.toolbar_button_onmouseover(event['data']);\n",
       "    }\n",
       "\n",
       "    for(var toolbar_ind in mpl.toolbar_items) {\n",
       "        var name = mpl.toolbar_items[toolbar_ind][0];\n",
       "        var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
       "        var image = mpl.toolbar_items[toolbar_ind][2];\n",
       "        var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
       "\n",
       "        if (!name) {\n",
       "            // put a spacer in here.\n",
       "            continue;\n",
       "        }\n",
       "        var button = $('<button/>');\n",
       "        button.addClass('ui-button ui-widget ui-state-default ui-corner-all ' +\n",
       "                        'ui-button-icon-only');\n",
       "        button.attr('role', 'button');\n",
       "        button.attr('aria-disabled', 'false');\n",
       "        button.click(method_name, toolbar_event);\n",
       "        button.mouseover(tooltip, toolbar_mouse_event);\n",
       "\n",
       "        var icon_img = $('<span/>');\n",
       "        icon_img.addClass('ui-button-icon-primary ui-icon');\n",
       "        icon_img.addClass(image);\n",
       "        icon_img.addClass('ui-corner-all');\n",
       "\n",
       "        var tooltip_span = $('<span/>');\n",
       "        tooltip_span.addClass('ui-button-text');\n",
       "        tooltip_span.html(tooltip);\n",
       "\n",
       "        button.append(icon_img);\n",
       "        button.append(tooltip_span);\n",
       "\n",
       "        nav_element.append(button);\n",
       "    }\n",
       "\n",
       "    var fmt_picker_span = $('<span/>');\n",
       "\n",
       "    var fmt_picker = $('<select/>');\n",
       "    fmt_picker.addClass('mpl-toolbar-option ui-widget ui-widget-content');\n",
       "    fmt_picker_span.append(fmt_picker);\n",
       "    nav_element.append(fmt_picker_span);\n",
       "    this.format_dropdown = fmt_picker[0];\n",
       "\n",
       "    for (var ind in mpl.extensions) {\n",
       "        var fmt = mpl.extensions[ind];\n",
       "        var option = $(\n",
       "            '<option/>', {selected: fmt === mpl.default_extension}).html(fmt);\n",
       "        fmt_picker.append(option)\n",
       "    }\n",
       "\n",
       "    // Add hover states to the ui-buttons\n",
       "    $( \".ui-button\" ).hover(\n",
       "        function() { $(this).addClass(\"ui-state-hover\");},\n",
       "        function() { $(this).removeClass(\"ui-state-hover\");}\n",
       "    );\n",
       "\n",
       "    var status_bar = $('<span class=\"mpl-message\"/>');\n",
       "    nav_element.append(status_bar);\n",
       "    this.message = status_bar[0];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.request_resize = function(x_pixels, y_pixels) {\n",
       "    // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n",
       "    // which will in turn request a refresh of the image.\n",
       "    this.send_message('resize', {'width': x_pixels, 'height': y_pixels});\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.send_message = function(type, properties) {\n",
       "    properties['type'] = type;\n",
       "    properties['figure_id'] = this.id;\n",
       "    this.ws.send(JSON.stringify(properties));\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.send_draw_message = function() {\n",
       "    if (!this.waiting) {\n",
       "        this.waiting = true;\n",
       "        this.ws.send(JSON.stringify({type: \"draw\", figure_id: this.id}));\n",
       "    }\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
       "    var format_dropdown = fig.format_dropdown;\n",
       "    var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n",
       "    fig.ondownload(fig, format);\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype.handle_resize = function(fig, msg) {\n",
       "    var size = msg['size'];\n",
       "    if (size[0] != fig.canvas.width || size[1] != fig.canvas.height) {\n",
       "        fig._resize_canvas(size[0], size[1]);\n",
       "        fig.send_message(\"refresh\", {});\n",
       "    };\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_rubberband = function(fig, msg) {\n",
       "    var x0 = msg['x0'] / mpl.ratio;\n",
       "    var y0 = (fig.canvas.height - msg['y0']) / mpl.ratio;\n",
       "    var x1 = msg['x1'] / mpl.ratio;\n",
       "    var y1 = (fig.canvas.height - msg['y1']) / mpl.ratio;\n",
       "    x0 = Math.floor(x0) + 0.5;\n",
       "    y0 = Math.floor(y0) + 0.5;\n",
       "    x1 = Math.floor(x1) + 0.5;\n",
       "    y1 = Math.floor(y1) + 0.5;\n",
       "    var min_x = Math.min(x0, x1);\n",
       "    var min_y = Math.min(y0, y1);\n",
       "    var width = Math.abs(x1 - x0);\n",
       "    var height = Math.abs(y1 - y0);\n",
       "\n",
       "    fig.rubberband_context.clearRect(\n",
       "        0, 0, fig.canvas.width, fig.canvas.height);\n",
       "\n",
       "    fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_figure_label = function(fig, msg) {\n",
       "    // Updates the figure title.\n",
       "    fig.header.textContent = msg['label'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_cursor = function(fig, msg) {\n",
       "    var cursor = msg['cursor'];\n",
       "    switch(cursor)\n",
       "    {\n",
       "    case 0:\n",
       "        cursor = 'pointer';\n",
       "        break;\n",
       "    case 1:\n",
       "        cursor = 'default';\n",
       "        break;\n",
       "    case 2:\n",
       "        cursor = 'crosshair';\n",
       "        break;\n",
       "    case 3:\n",
       "        cursor = 'move';\n",
       "        break;\n",
       "    }\n",
       "    fig.rubberband_canvas.style.cursor = cursor;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_message = function(fig, msg) {\n",
       "    fig.message.textContent = msg['message'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_draw = function(fig, msg) {\n",
       "    // Request the server to send over a new figure.\n",
       "    fig.send_draw_message();\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_image_mode = function(fig, msg) {\n",
       "    fig.image_mode = msg['mode'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.updated_canvas_event = function() {\n",
       "    // Called whenever the canvas gets updated.\n",
       "    this.send_message(\"ack\", {});\n",
       "}\n",
       "\n",
       "// A function to construct a web socket function for onmessage handling.\n",
       "// Called in the figure constructor.\n",
       "mpl.figure.prototype._make_on_message_function = function(fig) {\n",
       "    return function socket_on_message(evt) {\n",
       "        if (evt.data instanceof Blob) {\n",
       "            /* FIXME: We get \"Resource interpreted as Image but\n",
       "             * transferred with MIME type text/plain:\" errors on\n",
       "             * Chrome.  But how to set the MIME type?  It doesn't seem\n",
       "             * to be part of the websocket stream */\n",
       "            evt.data.type = \"image/png\";\n",
       "\n",
       "            /* Free the memory for the previous frames */\n",
       "            if (fig.imageObj.src) {\n",
       "                (window.URL || window.webkitURL).revokeObjectURL(\n",
       "                    fig.imageObj.src);\n",
       "            }\n",
       "\n",
       "            fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n",
       "                evt.data);\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        }\n",
       "        else if (typeof evt.data === 'string' && evt.data.slice(0, 21) == \"data:image/png;base64\") {\n",
       "            fig.imageObj.src = evt.data;\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        var msg = JSON.parse(evt.data);\n",
       "        var msg_type = msg['type'];\n",
       "\n",
       "        // Call the  \"handle_{type}\" callback, which takes\n",
       "        // the figure and JSON message as its only arguments.\n",
       "        try {\n",
       "            var callback = fig[\"handle_\" + msg_type];\n",
       "        } catch (e) {\n",
       "            console.log(\"No handler for the '\" + msg_type + \"' message type: \", msg);\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        if (callback) {\n",
       "            try {\n",
       "                // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n",
       "                callback(fig, msg);\n",
       "            } catch (e) {\n",
       "                console.log(\"Exception inside the 'handler_\" + msg_type + \"' callback:\", e, e.stack, msg);\n",
       "            }\n",
       "        }\n",
       "    };\n",
       "}\n",
       "\n",
       "// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas\n",
       "mpl.findpos = function(e) {\n",
       "    //this section is from http://www.quirksmode.org/js/events_properties.html\n",
       "    var targ;\n",
       "    if (!e)\n",
       "        e = window.event;\n",
       "    if (e.target)\n",
       "        targ = e.target;\n",
       "    else if (e.srcElement)\n",
       "        targ = e.srcElement;\n",
       "    if (targ.nodeType == 3) // defeat Safari bug\n",
       "        targ = targ.parentNode;\n",
       "\n",
       "    // jQuery normalizes the pageX and pageY\n",
       "    // pageX,Y are the mouse positions relative to the document\n",
       "    // offset() returns the position of the element relative to the document\n",
       "    var x = e.pageX - $(targ).offset().left;\n",
       "    var y = e.pageY - $(targ).offset().top;\n",
       "\n",
       "    return {\"x\": x, \"y\": y};\n",
       "};\n",
       "\n",
       "/*\n",
       " * return a copy of an object with only non-object keys\n",
       " * we need this to avoid circular references\n",
       " * http://stackoverflow.com/a/24161582/3208463\n",
       " */\n",
       "function simpleKeys (original) {\n",
       "  return Object.keys(original).reduce(function (obj, key) {\n",
       "    if (typeof original[key] !== 'object')\n",
       "        obj[key] = original[key]\n",
       "    return obj;\n",
       "  }, {});\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.mouse_event = function(event, name) {\n",
       "    var canvas_pos = mpl.findpos(event)\n",
       "\n",
       "    if (name === 'button_press')\n",
       "    {\n",
       "        this.canvas.focus();\n",
       "        this.canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    var x = canvas_pos.x * mpl.ratio;\n",
       "    var y = canvas_pos.y * mpl.ratio;\n",
       "\n",
       "    this.send_message(name, {x: x, y: y, button: event.button,\n",
       "                             step: event.step,\n",
       "                             guiEvent: simpleKeys(event)});\n",
       "\n",
       "    /* This prevents the web browser from automatically changing to\n",
       "     * the text insertion cursor when the button is pressed.  We want\n",
       "     * to control all of the cursor setting manually through the\n",
       "     * 'cursor' event from matplotlib */\n",
       "    event.preventDefault();\n",
       "    return false;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
       "    // Handle any extra behaviour associated with a key event\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.key_event = function(event, name) {\n",
       "\n",
       "    // Prevent repeat events\n",
       "    if (name == 'key_press')\n",
       "    {\n",
       "        if (event.which === this._key)\n",
       "            return;\n",
       "        else\n",
       "            this._key = event.which;\n",
       "    }\n",
       "    if (name == 'key_release')\n",
       "        this._key = null;\n",
       "\n",
       "    var value = '';\n",
       "    if (event.ctrlKey && event.which != 17)\n",
       "        value += \"ctrl+\";\n",
       "    if (event.altKey && event.which != 18)\n",
       "        value += \"alt+\";\n",
       "    if (event.shiftKey && event.which != 16)\n",
       "        value += \"shift+\";\n",
       "\n",
       "    value += 'k';\n",
       "    value += event.which.toString();\n",
       "\n",
       "    this._key_event_extra(event, name);\n",
       "\n",
       "    this.send_message(name, {key: value,\n",
       "                             guiEvent: simpleKeys(event)});\n",
       "    return false;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.toolbar_button_onclick = function(name) {\n",
       "    if (name == 'download') {\n",
       "        this.handle_save(this, null);\n",
       "    } else {\n",
       "        this.send_message(\"toolbar_button\", {name: name});\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.toolbar_button_onmouseover = function(tooltip) {\n",
       "    this.message.textContent = tooltip;\n",
       "};\n",
       "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Pan axes with left mouse, zoom with right\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n",
       "\n",
       "mpl.extensions = [\"eps\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\"];\n",
       "\n",
       "mpl.default_extension = \"png\";var comm_websocket_adapter = function(comm) {\n",
       "    // Create a \"websocket\"-like object which calls the given IPython comm\n",
       "    // object with the appropriate methods. Currently this is a non binary\n",
       "    // socket, so there is still some room for performance tuning.\n",
       "    var ws = {};\n",
       "\n",
       "    ws.close = function() {\n",
       "        comm.close()\n",
       "    };\n",
       "    ws.send = function(m) {\n",
       "        //console.log('sending', m);\n",
       "        comm.send(m);\n",
       "    };\n",
       "    // Register the callback with on_msg.\n",
       "    comm.on_msg(function(msg) {\n",
       "        //console.log('receiving', msg['content']['data'], msg);\n",
       "        // Pass the mpl event to the overridden (by mpl) onmessage function.\n",
       "        ws.onmessage(msg['content']['data'])\n",
       "    });\n",
       "    return ws;\n",
       "}\n",
       "\n",
       "mpl.mpl_figure_comm = function(comm, msg) {\n",
       "    // This is the function which gets called when the mpl process\n",
       "    // starts-up an IPython Comm through the \"matplotlib\" channel.\n",
       "\n",
       "    var id = msg.content.data.id;\n",
       "    // Get hold of the div created by the display call when the Comm\n",
       "    // socket was opened in Python.\n",
       "    var element = $(\"#\" + id);\n",
       "    var ws_proxy = comm_websocket_adapter(comm)\n",
       "\n",
       "    function ondownload(figure, format) {\n",
       "        window.open(figure.imageObj.src);\n",
       "    }\n",
       "\n",
       "    var fig = new mpl.figure(id, ws_proxy,\n",
       "                           ondownload,\n",
       "                           element.get(0));\n",
       "\n",
       "    // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n",
       "    // web socket which is closed, not our websocket->open comm proxy.\n",
       "    ws_proxy.onopen();\n",
       "\n",
       "    fig.parent_element = element.get(0);\n",
       "    fig.cell_info = mpl.find_output_cell(\"<div id='\" + id + \"'></div>\");\n",
       "    if (!fig.cell_info) {\n",
       "        console.error(\"Failed to find cell for figure\", id, fig);\n",
       "        return;\n",
       "    }\n",
       "\n",
       "    var output_index = fig.cell_info[2]\n",
       "    var cell = fig.cell_info[0];\n",
       "\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_close = function(fig, msg) {\n",
       "    var width = fig.canvas.width/mpl.ratio\n",
       "    fig.root.unbind('remove')\n",
       "\n",
       "    // Update the output cell to use the data from the current canvas.\n",
       "    fig.push_to_output();\n",
       "    var dataURL = fig.canvas.toDataURL();\n",
       "    // Re-enable the keyboard manager in IPython - without this line, in FF,\n",
       "    // the notebook keyboard shortcuts fail.\n",
       "    IPython.keyboard_manager.enable()\n",
       "    $(fig.parent_element).html('<img src=\"' + dataURL + '\" width=\"' + width + '\">');\n",
       "    fig.close_ws(fig, msg);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.close_ws = function(fig, msg){\n",
       "    fig.send_message('closing', msg);\n",
       "    // fig.ws.close()\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.push_to_output = function(remove_interactive) {\n",
       "    // Turn the data on the canvas into data in the output cell.\n",
       "    var width = this.canvas.width/mpl.ratio\n",
       "    var dataURL = this.canvas.toDataURL();\n",
       "    this.cell_info[1]['text/html'] = '<img src=\"' + dataURL + '\" width=\"' + width + '\">';\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.updated_canvas_event = function() {\n",
       "    // Tell IPython that the notebook contents must change.\n",
       "    IPython.notebook.set_dirty(true);\n",
       "    this.send_message(\"ack\", {});\n",
       "    var fig = this;\n",
       "    // Wait a second, then push the new image to the DOM so\n",
       "    // that it is saved nicely (might be nice to debounce this).\n",
       "    setTimeout(function () { fig.push_to_output() }, 1000);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_toolbar = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var nav_element = $('<div/>')\n",
       "    nav_element.attr('style', 'width: 100%');\n",
       "    this.root.append(nav_element);\n",
       "\n",
       "    // Define a callback function for later on.\n",
       "    function toolbar_event(event) {\n",
       "        return fig.toolbar_button_onclick(event['data']);\n",
       "    }\n",
       "    function toolbar_mouse_event(event) {\n",
       "        return fig.toolbar_button_onmouseover(event['data']);\n",
       "    }\n",
       "\n",
       "    for(var toolbar_ind in mpl.toolbar_items){\n",
       "        var name = mpl.toolbar_items[toolbar_ind][0];\n",
       "        var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
       "        var image = mpl.toolbar_items[toolbar_ind][2];\n",
       "        var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
       "\n",
       "        if (!name) { continue; };\n",
       "\n",
       "        var button = $('<button class=\"btn btn-default\" href=\"#\" title=\"' + name + '\"><i class=\"fa ' + image + ' fa-lg\"></i></button>');\n",
       "        button.click(method_name, toolbar_event);\n",
       "        button.mouseover(tooltip, toolbar_mouse_event);\n",
       "        nav_element.append(button);\n",
       "    }\n",
       "\n",
       "    // Add the status bar.\n",
       "    var status_bar = $('<span class=\"mpl-message\" style=\"text-align:right; float: right;\"/>');\n",
       "    nav_element.append(status_bar);\n",
       "    this.message = status_bar[0];\n",
       "\n",
       "    // Add the close button to the window.\n",
       "    var buttongrp = $('<div class=\"btn-group inline pull-right\"></div>');\n",
       "    var button = $('<button class=\"btn btn-mini btn-primary\" href=\"#\" title=\"Stop Interaction\"><i class=\"fa fa-power-off icon-remove icon-large\"></i></button>');\n",
       "    button.click(function (evt) { fig.handle_close(fig, {}); } );\n",
       "    button.mouseover('Stop Interaction', toolbar_mouse_event);\n",
       "    buttongrp.append(button);\n",
       "    var titlebar = this.root.find($('.ui-dialog-titlebar'));\n",
       "    titlebar.prepend(buttongrp);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._root_extra_style = function(el){\n",
       "    var fig = this\n",
       "    el.on(\"remove\", function(){\n",
       "\tfig.close_ws(fig, {});\n",
       "    });\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._canvas_extra_style = function(el){\n",
       "    // this is important to make the div 'focusable\n",
       "    el.attr('tabindex', 0)\n",
       "    // reach out to IPython and tell the keyboard manager to turn it's self\n",
       "    // off when our div gets focus\n",
       "\n",
       "    // location in version 3\n",
       "    if (IPython.notebook.keyboard_manager) {\n",
       "        IPython.notebook.keyboard_manager.register_events(el);\n",
       "    }\n",
       "    else {\n",
       "        // location in version 2\n",
       "        IPython.keyboard_manager.register_events(el);\n",
       "    }\n",
       "\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
       "    var manager = IPython.notebook.keyboard_manager;\n",
       "    if (!manager)\n",
       "        manager = IPython.keyboard_manager;\n",
       "\n",
       "    // Check for shift+enter\n",
       "    if (event.shiftKey && event.which == 13) {\n",
       "        this.canvas_div.blur();\n",
       "        event.shiftKey = false;\n",
       "        // Send a \"J\" for go to next cell\n",
       "        event.which = 74;\n",
       "        event.keyCode = 74;\n",
       "        manager.command_mode();\n",
       "        manager.handle_keydown(event);\n",
       "    }\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
       "    fig.ondownload(fig, null);\n",
       "}\n",
       "\n",
       "\n",
       "mpl.find_output_cell = function(html_output) {\n",
       "    // Return the cell and output element which can be found *uniquely* in the notebook.\n",
       "    // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n",
       "    // IPython event is triggered only after the cells have been serialised, which for\n",
       "    // our purposes (turning an active figure into a static one), is too late.\n",
       "    var cells = IPython.notebook.get_cells();\n",
       "    var ncells = cells.length;\n",
       "    for (var i=0; i<ncells; i++) {\n",
       "        var cell = cells[i];\n",
       "        if (cell.cell_type === 'code'){\n",
       "            for (var j=0; j<cell.output_area.outputs.length; j++) {\n",
       "                var data = cell.output_area.outputs[j];\n",
       "                if (data.data) {\n",
       "                    // IPython >= 3 moved mimebundle to data attribute of output\n",
       "                    data = data.data;\n",
       "                }\n",
       "                if (data['text/html'] == html_output) {\n",
       "                    return [cell, data, j];\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    }\n",
       "}\n",
       "\n",
       "// Register the function which deals with the matplotlib target/channel.\n",
       "// The kernel may be null if the page has been refreshed.\n",
       "if (IPython.notebook.kernel != null) {\n",
       "    IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n",
       "}\n"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<img src=\"\" width=\"400\">"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_____\n",
      "model: ens \n",
      "\n",
      "mean best epoc: [19.33333333]\n",
      "mean training time: [153.17728448]\n",
      "STATS:\n",
      "acc           0.957093\n",
      "auc           0.989579\n",
      "loss          0.111965\n",
      "lr            0.000063\n",
      "recall        0.996432\n",
      "val_acc       0.905280\n",
      "val_auc       0.989751\n",
      "val_loss      0.310829\n",
      "val_recall    0.996519\n",
      "dtype: float64\n",
      "\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/javascript": [
       "/* Put everything inside the global mpl namespace */\n",
       "window.mpl = {};\n",
       "\n",
       "\n",
       "mpl.get_websocket_type = function() {\n",
       "    if (typeof(WebSocket) !== 'undefined') {\n",
       "        return WebSocket;\n",
       "    } else if (typeof(MozWebSocket) !== 'undefined') {\n",
       "        return MozWebSocket;\n",
       "    } else {\n",
       "        alert('Your browser does not have WebSocket support.' +\n",
       "              'Please try Chrome, Safari or Firefox ≥ 6. ' +\n",
       "              'Firefox 4 and 5 are also supported but you ' +\n",
       "              'have to enable WebSockets in about:config.');\n",
       "    };\n",
       "}\n",
       "\n",
       "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n",
       "    this.id = figure_id;\n",
       "\n",
       "    this.ws = websocket;\n",
       "\n",
       "    this.supports_binary = (this.ws.binaryType != undefined);\n",
       "\n",
       "    if (!this.supports_binary) {\n",
       "        var warnings = document.getElementById(\"mpl-warnings\");\n",
       "        if (warnings) {\n",
       "            warnings.style.display = 'block';\n",
       "            warnings.textContent = (\n",
       "                \"This browser does not support binary websocket messages. \" +\n",
       "                    \"Performance may be slow.\");\n",
       "        }\n",
       "    }\n",
       "\n",
       "    this.imageObj = new Image();\n",
       "\n",
       "    this.context = undefined;\n",
       "    this.message = undefined;\n",
       "    this.canvas = undefined;\n",
       "    this.rubberband_canvas = undefined;\n",
       "    this.rubberband_context = undefined;\n",
       "    this.format_dropdown = undefined;\n",
       "\n",
       "    this.image_mode = 'full';\n",
       "\n",
       "    this.root = $('<div/>');\n",
       "    this._root_extra_style(this.root)\n",
       "    this.root.attr('style', 'display: inline-block');\n",
       "\n",
       "    $(parent_element).append(this.root);\n",
       "\n",
       "    this._init_header(this);\n",
       "    this._init_canvas(this);\n",
       "    this._init_toolbar(this);\n",
       "\n",
       "    var fig = this;\n",
       "\n",
       "    this.waiting = false;\n",
       "\n",
       "    this.ws.onopen =  function () {\n",
       "            fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n",
       "            fig.send_message(\"send_image_mode\", {});\n",
       "            if (mpl.ratio != 1) {\n",
       "                fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n",
       "            }\n",
       "            fig.send_message(\"refresh\", {});\n",
       "        }\n",
       "\n",
       "    this.imageObj.onload = function() {\n",
       "            if (fig.image_mode == 'full') {\n",
       "                // Full images could contain transparency (where diff images\n",
       "                // almost always do), so we need to clear the canvas so that\n",
       "                // there is no ghosting.\n",
       "                fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n",
       "            }\n",
       "            fig.context.drawImage(fig.imageObj, 0, 0);\n",
       "        };\n",
       "\n",
       "    this.imageObj.onunload = function() {\n",
       "        fig.ws.close();\n",
       "    }\n",
       "\n",
       "    this.ws.onmessage = this._make_on_message_function(this);\n",
       "\n",
       "    this.ondownload = ondownload;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_header = function() {\n",
       "    var titlebar = $(\n",
       "        '<div class=\"ui-dialog-titlebar ui-widget-header ui-corner-all ' +\n",
       "        'ui-helper-clearfix\"/>');\n",
       "    var titletext = $(\n",
       "        '<div class=\"ui-dialog-title\" style=\"width: 100%; ' +\n",
       "        'text-align: center; padding: 3px;\"/>');\n",
       "    titlebar.append(titletext)\n",
       "    this.root.append(titlebar);\n",
       "    this.header = titletext[0];\n",
       "}\n",
       "\n",
       "\n",
       "\n",
       "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n",
       "\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n",
       "\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_canvas = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var canvas_div = $('<div/>');\n",
       "\n",
       "    canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n",
       "\n",
       "    function canvas_keyboard_event(event) {\n",
       "        return fig.key_event(event, event['data']);\n",
       "    }\n",
       "\n",
       "    canvas_div.keydown('key_press', canvas_keyboard_event);\n",
       "    canvas_div.keyup('key_release', canvas_keyboard_event);\n",
       "    this.canvas_div = canvas_div\n",
       "    this._canvas_extra_style(canvas_div)\n",
       "    this.root.append(canvas_div);\n",
       "\n",
       "    var canvas = $('<canvas/>');\n",
       "    canvas.addClass('mpl-canvas');\n",
       "    canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n",
       "\n",
       "    this.canvas = canvas[0];\n",
       "    this.context = canvas[0].getContext(\"2d\");\n",
       "\n",
       "    var backingStore = this.context.backingStorePixelRatio ||\n",
       "\tthis.context.webkitBackingStorePixelRatio ||\n",
       "\tthis.context.mozBackingStorePixelRatio ||\n",
       "\tthis.context.msBackingStorePixelRatio ||\n",
       "\tthis.context.oBackingStorePixelRatio ||\n",
       "\tthis.context.backingStorePixelRatio || 1;\n",
       "\n",
       "    mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n",
       "\n",
       "    var rubberband = $('<canvas/>');\n",
       "    rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n",
       "\n",
       "    var pass_mouse_events = true;\n",
       "\n",
       "    canvas_div.resizable({\n",
       "        start: function(event, ui) {\n",
       "            pass_mouse_events = false;\n",
       "        },\n",
       "        resize: function(event, ui) {\n",
       "            fig.request_resize(ui.size.width, ui.size.height);\n",
       "        },\n",
       "        stop: function(event, ui) {\n",
       "            pass_mouse_events = true;\n",
       "            fig.request_resize(ui.size.width, ui.size.height);\n",
       "        },\n",
       "    });\n",
       "\n",
       "    function mouse_event_fn(event) {\n",
       "        if (pass_mouse_events)\n",
       "            return fig.mouse_event(event, event['data']);\n",
       "    }\n",
       "\n",
       "    rubberband.mousedown('button_press', mouse_event_fn);\n",
       "    rubberband.mouseup('button_release', mouse_event_fn);\n",
       "    // Throttle sequential mouse events to 1 every 20ms.\n",
       "    rubberband.mousemove('motion_notify', mouse_event_fn);\n",
       "\n",
       "    rubberband.mouseenter('figure_enter', mouse_event_fn);\n",
       "    rubberband.mouseleave('figure_leave', mouse_event_fn);\n",
       "\n",
       "    canvas_div.on(\"wheel\", function (event) {\n",
       "        event = event.originalEvent;\n",
       "        event['data'] = 'scroll'\n",
       "        if (event.deltaY < 0) {\n",
       "            event.step = 1;\n",
       "        } else {\n",
       "            event.step = -1;\n",
       "        }\n",
       "        mouse_event_fn(event);\n",
       "    });\n",
       "\n",
       "    canvas_div.append(canvas);\n",
       "    canvas_div.append(rubberband);\n",
       "\n",
       "    this.rubberband = rubberband;\n",
       "    this.rubberband_canvas = rubberband[0];\n",
       "    this.rubberband_context = rubberband[0].getContext(\"2d\");\n",
       "    this.rubberband_context.strokeStyle = \"#000000\";\n",
       "\n",
       "    this._resize_canvas = function(width, height) {\n",
       "        // Keep the size of the canvas, canvas container, and rubber band\n",
       "        // canvas in synch.\n",
       "        canvas_div.css('width', width)\n",
       "        canvas_div.css('height', height)\n",
       "\n",
       "        canvas.attr('width', width * mpl.ratio);\n",
       "        canvas.attr('height', height * mpl.ratio);\n",
       "        canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n",
       "\n",
       "        rubberband.attr('width', width);\n",
       "        rubberband.attr('height', height);\n",
       "    }\n",
       "\n",
       "    // Set the figure to an initial 600x600px, this will subsequently be updated\n",
       "    // upon first draw.\n",
       "    this._resize_canvas(600, 600);\n",
       "\n",
       "    // Disable right mouse context menu.\n",
       "    $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n",
       "        return false;\n",
       "    });\n",
       "\n",
       "    function set_focus () {\n",
       "        canvas.focus();\n",
       "        canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    window.setTimeout(set_focus, 100);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_toolbar = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var nav_element = $('<div/>')\n",
       "    nav_element.attr('style', 'width: 100%');\n",
       "    this.root.append(nav_element);\n",
       "\n",
       "    // Define a callback function for later on.\n",
       "    function toolbar_event(event) {\n",
       "        return fig.toolbar_button_onclick(event['data']);\n",
       "    }\n",
       "    function toolbar_mouse_event(event) {\n",
       "        return fig.toolbar_button_onmouseover(event['data']);\n",
       "    }\n",
       "\n",
       "    for(var toolbar_ind in mpl.toolbar_items) {\n",
       "        var name = mpl.toolbar_items[toolbar_ind][0];\n",
       "        var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
       "        var image = mpl.toolbar_items[toolbar_ind][2];\n",
       "        var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
       "\n",
       "        if (!name) {\n",
       "            // put a spacer in here.\n",
       "            continue;\n",
       "        }\n",
       "        var button = $('<button/>');\n",
       "        button.addClass('ui-button ui-widget ui-state-default ui-corner-all ' +\n",
       "                        'ui-button-icon-only');\n",
       "        button.attr('role', 'button');\n",
       "        button.attr('aria-disabled', 'false');\n",
       "        button.click(method_name, toolbar_event);\n",
       "        button.mouseover(tooltip, toolbar_mouse_event);\n",
       "\n",
       "        var icon_img = $('<span/>');\n",
       "        icon_img.addClass('ui-button-icon-primary ui-icon');\n",
       "        icon_img.addClass(image);\n",
       "        icon_img.addClass('ui-corner-all');\n",
       "\n",
       "        var tooltip_span = $('<span/>');\n",
       "        tooltip_span.addClass('ui-button-text');\n",
       "        tooltip_span.html(tooltip);\n",
       "\n",
       "        button.append(icon_img);\n",
       "        button.append(tooltip_span);\n",
       "\n",
       "        nav_element.append(button);\n",
       "    }\n",
       "\n",
       "    var fmt_picker_span = $('<span/>');\n",
       "\n",
       "    var fmt_picker = $('<select/>');\n",
       "    fmt_picker.addClass('mpl-toolbar-option ui-widget ui-widget-content');\n",
       "    fmt_picker_span.append(fmt_picker);\n",
       "    nav_element.append(fmt_picker_span);\n",
       "    this.format_dropdown = fmt_picker[0];\n",
       "\n",
       "    for (var ind in mpl.extensions) {\n",
       "        var fmt = mpl.extensions[ind];\n",
       "        var option = $(\n",
       "            '<option/>', {selected: fmt === mpl.default_extension}).html(fmt);\n",
       "        fmt_picker.append(option)\n",
       "    }\n",
       "\n",
       "    // Add hover states to the ui-buttons\n",
       "    $( \".ui-button\" ).hover(\n",
       "        function() { $(this).addClass(\"ui-state-hover\");},\n",
       "        function() { $(this).removeClass(\"ui-state-hover\");}\n",
       "    );\n",
       "\n",
       "    var status_bar = $('<span class=\"mpl-message\"/>');\n",
       "    nav_element.append(status_bar);\n",
       "    this.message = status_bar[0];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.request_resize = function(x_pixels, y_pixels) {\n",
       "    // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n",
       "    // which will in turn request a refresh of the image.\n",
       "    this.send_message('resize', {'width': x_pixels, 'height': y_pixels});\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.send_message = function(type, properties) {\n",
       "    properties['type'] = type;\n",
       "    properties['figure_id'] = this.id;\n",
       "    this.ws.send(JSON.stringify(properties));\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.send_draw_message = function() {\n",
       "    if (!this.waiting) {\n",
       "        this.waiting = true;\n",
       "        this.ws.send(JSON.stringify({type: \"draw\", figure_id: this.id}));\n",
       "    }\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
       "    var format_dropdown = fig.format_dropdown;\n",
       "    var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n",
       "    fig.ondownload(fig, format);\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype.handle_resize = function(fig, msg) {\n",
       "    var size = msg['size'];\n",
       "    if (size[0] != fig.canvas.width || size[1] != fig.canvas.height) {\n",
       "        fig._resize_canvas(size[0], size[1]);\n",
       "        fig.send_message(\"refresh\", {});\n",
       "    };\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_rubberband = function(fig, msg) {\n",
       "    var x0 = msg['x0'] / mpl.ratio;\n",
       "    var y0 = (fig.canvas.height - msg['y0']) / mpl.ratio;\n",
       "    var x1 = msg['x1'] / mpl.ratio;\n",
       "    var y1 = (fig.canvas.height - msg['y1']) / mpl.ratio;\n",
       "    x0 = Math.floor(x0) + 0.5;\n",
       "    y0 = Math.floor(y0) + 0.5;\n",
       "    x1 = Math.floor(x1) + 0.5;\n",
       "    y1 = Math.floor(y1) + 0.5;\n",
       "    var min_x = Math.min(x0, x1);\n",
       "    var min_y = Math.min(y0, y1);\n",
       "    var width = Math.abs(x1 - x0);\n",
       "    var height = Math.abs(y1 - y0);\n",
       "\n",
       "    fig.rubberband_context.clearRect(\n",
       "        0, 0, fig.canvas.width, fig.canvas.height);\n",
       "\n",
       "    fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_figure_label = function(fig, msg) {\n",
       "    // Updates the figure title.\n",
       "    fig.header.textContent = msg['label'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_cursor = function(fig, msg) {\n",
       "    var cursor = msg['cursor'];\n",
       "    switch(cursor)\n",
       "    {\n",
       "    case 0:\n",
       "        cursor = 'pointer';\n",
       "        break;\n",
       "    case 1:\n",
       "        cursor = 'default';\n",
       "        break;\n",
       "    case 2:\n",
       "        cursor = 'crosshair';\n",
       "        break;\n",
       "    case 3:\n",
       "        cursor = 'move';\n",
       "        break;\n",
       "    }\n",
       "    fig.rubberband_canvas.style.cursor = cursor;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_message = function(fig, msg) {\n",
       "    fig.message.textContent = msg['message'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_draw = function(fig, msg) {\n",
       "    // Request the server to send over a new figure.\n",
       "    fig.send_draw_message();\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_image_mode = function(fig, msg) {\n",
       "    fig.image_mode = msg['mode'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.updated_canvas_event = function() {\n",
       "    // Called whenever the canvas gets updated.\n",
       "    this.send_message(\"ack\", {});\n",
       "}\n",
       "\n",
       "// A function to construct a web socket function for onmessage handling.\n",
       "// Called in the figure constructor.\n",
       "mpl.figure.prototype._make_on_message_function = function(fig) {\n",
       "    return function socket_on_message(evt) {\n",
       "        if (evt.data instanceof Blob) {\n",
       "            /* FIXME: We get \"Resource interpreted as Image but\n",
       "             * transferred with MIME type text/plain:\" errors on\n",
       "             * Chrome.  But how to set the MIME type?  It doesn't seem\n",
       "             * to be part of the websocket stream */\n",
       "            evt.data.type = \"image/png\";\n",
       "\n",
       "            /* Free the memory for the previous frames */\n",
       "            if (fig.imageObj.src) {\n",
       "                (window.URL || window.webkitURL).revokeObjectURL(\n",
       "                    fig.imageObj.src);\n",
       "            }\n",
       "\n",
       "            fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n",
       "                evt.data);\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        }\n",
       "        else if (typeof evt.data === 'string' && evt.data.slice(0, 21) == \"data:image/png;base64\") {\n",
       "            fig.imageObj.src = evt.data;\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        var msg = JSON.parse(evt.data);\n",
       "        var msg_type = msg['type'];\n",
       "\n",
       "        // Call the  \"handle_{type}\" callback, which takes\n",
       "        // the figure and JSON message as its only arguments.\n",
       "        try {\n",
       "            var callback = fig[\"handle_\" + msg_type];\n",
       "        } catch (e) {\n",
       "            console.log(\"No handler for the '\" + msg_type + \"' message type: \", msg);\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        if (callback) {\n",
       "            try {\n",
       "                // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n",
       "                callback(fig, msg);\n",
       "            } catch (e) {\n",
       "                console.log(\"Exception inside the 'handler_\" + msg_type + \"' callback:\", e, e.stack, msg);\n",
       "            }\n",
       "        }\n",
       "    };\n",
       "}\n",
       "\n",
       "// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas\n",
       "mpl.findpos = function(e) {\n",
       "    //this section is from http://www.quirksmode.org/js/events_properties.html\n",
       "    var targ;\n",
       "    if (!e)\n",
       "        e = window.event;\n",
       "    if (e.target)\n",
       "        targ = e.target;\n",
       "    else if (e.srcElement)\n",
       "        targ = e.srcElement;\n",
       "    if (targ.nodeType == 3) // defeat Safari bug\n",
       "        targ = targ.parentNode;\n",
       "\n",
       "    // jQuery normalizes the pageX and pageY\n",
       "    // pageX,Y are the mouse positions relative to the document\n",
       "    // offset() returns the position of the element relative to the document\n",
       "    var x = e.pageX - $(targ).offset().left;\n",
       "    var y = e.pageY - $(targ).offset().top;\n",
       "\n",
       "    return {\"x\": x, \"y\": y};\n",
       "};\n",
       "\n",
       "/*\n",
       " * return a copy of an object with only non-object keys\n",
       " * we need this to avoid circular references\n",
       " * http://stackoverflow.com/a/24161582/3208463\n",
       " */\n",
       "function simpleKeys (original) {\n",
       "  return Object.keys(original).reduce(function (obj, key) {\n",
       "    if (typeof original[key] !== 'object')\n",
       "        obj[key] = original[key]\n",
       "    return obj;\n",
       "  }, {});\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.mouse_event = function(event, name) {\n",
       "    var canvas_pos = mpl.findpos(event)\n",
       "\n",
       "    if (name === 'button_press')\n",
       "    {\n",
       "        this.canvas.focus();\n",
       "        this.canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    var x = canvas_pos.x * mpl.ratio;\n",
       "    var y = canvas_pos.y * mpl.ratio;\n",
       "\n",
       "    this.send_message(name, {x: x, y: y, button: event.button,\n",
       "                             step: event.step,\n",
       "                             guiEvent: simpleKeys(event)});\n",
       "\n",
       "    /* This prevents the web browser from automatically changing to\n",
       "     * the text insertion cursor when the button is pressed.  We want\n",
       "     * to control all of the cursor setting manually through the\n",
       "     * 'cursor' event from matplotlib */\n",
       "    event.preventDefault();\n",
       "    return false;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
       "    // Handle any extra behaviour associated with a key event\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.key_event = function(event, name) {\n",
       "\n",
       "    // Prevent repeat events\n",
       "    if (name == 'key_press')\n",
       "    {\n",
       "        if (event.which === this._key)\n",
       "            return;\n",
       "        else\n",
       "            this._key = event.which;\n",
       "    }\n",
       "    if (name == 'key_release')\n",
       "        this._key = null;\n",
       "\n",
       "    var value = '';\n",
       "    if (event.ctrlKey && event.which != 17)\n",
       "        value += \"ctrl+\";\n",
       "    if (event.altKey && event.which != 18)\n",
       "        value += \"alt+\";\n",
       "    if (event.shiftKey && event.which != 16)\n",
       "        value += \"shift+\";\n",
       "\n",
       "    value += 'k';\n",
       "    value += event.which.toString();\n",
       "\n",
       "    this._key_event_extra(event, name);\n",
       "\n",
       "    this.send_message(name, {key: value,\n",
       "                             guiEvent: simpleKeys(event)});\n",
       "    return false;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.toolbar_button_onclick = function(name) {\n",
       "    if (name == 'download') {\n",
       "        this.handle_save(this, null);\n",
       "    } else {\n",
       "        this.send_message(\"toolbar_button\", {name: name});\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.toolbar_button_onmouseover = function(tooltip) {\n",
       "    this.message.textContent = tooltip;\n",
       "};\n",
       "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Pan axes with left mouse, zoom with right\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n",
       "\n",
       "mpl.extensions = [\"eps\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\"];\n",
       "\n",
       "mpl.default_extension = \"png\";var comm_websocket_adapter = function(comm) {\n",
       "    // Create a \"websocket\"-like object which calls the given IPython comm\n",
       "    // object with the appropriate methods. Currently this is a non binary\n",
       "    // socket, so there is still some room for performance tuning.\n",
       "    var ws = {};\n",
       "\n",
       "    ws.close = function() {\n",
       "        comm.close()\n",
       "    };\n",
       "    ws.send = function(m) {\n",
       "        //console.log('sending', m);\n",
       "        comm.send(m);\n",
       "    };\n",
       "    // Register the callback with on_msg.\n",
       "    comm.on_msg(function(msg) {\n",
       "        //console.log('receiving', msg['content']['data'], msg);\n",
       "        // Pass the mpl event to the overridden (by mpl) onmessage function.\n",
       "        ws.onmessage(msg['content']['data'])\n",
       "    });\n",
       "    return ws;\n",
       "}\n",
       "\n",
       "mpl.mpl_figure_comm = function(comm, msg) {\n",
       "    // This is the function which gets called when the mpl process\n",
       "    // starts-up an IPython Comm through the \"matplotlib\" channel.\n",
       "\n",
       "    var id = msg.content.data.id;\n",
       "    // Get hold of the div created by the display call when the Comm\n",
       "    // socket was opened in Python.\n",
       "    var element = $(\"#\" + id);\n",
       "    var ws_proxy = comm_websocket_adapter(comm)\n",
       "\n",
       "    function ondownload(figure, format) {\n",
       "        window.open(figure.imageObj.src);\n",
       "    }\n",
       "\n",
       "    var fig = new mpl.figure(id, ws_proxy,\n",
       "                           ondownload,\n",
       "                           element.get(0));\n",
       "\n",
       "    // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n",
       "    // web socket which is closed, not our websocket->open comm proxy.\n",
       "    ws_proxy.onopen();\n",
       "\n",
       "    fig.parent_element = element.get(0);\n",
       "    fig.cell_info = mpl.find_output_cell(\"<div id='\" + id + \"'></div>\");\n",
       "    if (!fig.cell_info) {\n",
       "        console.error(\"Failed to find cell for figure\", id, fig);\n",
       "        return;\n",
       "    }\n",
       "\n",
       "    var output_index = fig.cell_info[2]\n",
       "    var cell = fig.cell_info[0];\n",
       "\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_close = function(fig, msg) {\n",
       "    var width = fig.canvas.width/mpl.ratio\n",
       "    fig.root.unbind('remove')\n",
       "\n",
       "    // Update the output cell to use the data from the current canvas.\n",
       "    fig.push_to_output();\n",
       "    var dataURL = fig.canvas.toDataURL();\n",
       "    // Re-enable the keyboard manager in IPython - without this line, in FF,\n",
       "    // the notebook keyboard shortcuts fail.\n",
       "    IPython.keyboard_manager.enable()\n",
       "    $(fig.parent_element).html('<img src=\"' + dataURL + '\" width=\"' + width + '\">');\n",
       "    fig.close_ws(fig, msg);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.close_ws = function(fig, msg){\n",
       "    fig.send_message('closing', msg);\n",
       "    // fig.ws.close()\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.push_to_output = function(remove_interactive) {\n",
       "    // Turn the data on the canvas into data in the output cell.\n",
       "    var width = this.canvas.width/mpl.ratio\n",
       "    var dataURL = this.canvas.toDataURL();\n",
       "    this.cell_info[1]['text/html'] = '<img src=\"' + dataURL + '\" width=\"' + width + '\">';\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.updated_canvas_event = function() {\n",
       "    // Tell IPython that the notebook contents must change.\n",
       "    IPython.notebook.set_dirty(true);\n",
       "    this.send_message(\"ack\", {});\n",
       "    var fig = this;\n",
       "    // Wait a second, then push the new image to the DOM so\n",
       "    // that it is saved nicely (might be nice to debounce this).\n",
       "    setTimeout(function () { fig.push_to_output() }, 1000);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_toolbar = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var nav_element = $('<div/>')\n",
       "    nav_element.attr('style', 'width: 100%');\n",
       "    this.root.append(nav_element);\n",
       "\n",
       "    // Define a callback function for later on.\n",
       "    function toolbar_event(event) {\n",
       "        return fig.toolbar_button_onclick(event['data']);\n",
       "    }\n",
       "    function toolbar_mouse_event(event) {\n",
       "        return fig.toolbar_button_onmouseover(event['data']);\n",
       "    }\n",
       "\n",
       "    for(var toolbar_ind in mpl.toolbar_items){\n",
       "        var name = mpl.toolbar_items[toolbar_ind][0];\n",
       "        var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
       "        var image = mpl.toolbar_items[toolbar_ind][2];\n",
       "        var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
       "\n",
       "        if (!name) { continue; };\n",
       "\n",
       "        var button = $('<button class=\"btn btn-default\" href=\"#\" title=\"' + name + '\"><i class=\"fa ' + image + ' fa-lg\"></i></button>');\n",
       "        button.click(method_name, toolbar_event);\n",
       "        button.mouseover(tooltip, toolbar_mouse_event);\n",
       "        nav_element.append(button);\n",
       "    }\n",
       "\n",
       "    // Add the status bar.\n",
       "    var status_bar = $('<span class=\"mpl-message\" style=\"text-align:right; float: right;\"/>');\n",
       "    nav_element.append(status_bar);\n",
       "    this.message = status_bar[0];\n",
       "\n",
       "    // Add the close button to the window.\n",
       "    var buttongrp = $('<div class=\"btn-group inline pull-right\"></div>');\n",
       "    var button = $('<button class=\"btn btn-mini btn-primary\" href=\"#\" title=\"Stop Interaction\"><i class=\"fa fa-power-off icon-remove icon-large\"></i></button>');\n",
       "    button.click(function (evt) { fig.handle_close(fig, {}); } );\n",
       "    button.mouseover('Stop Interaction', toolbar_mouse_event);\n",
       "    buttongrp.append(button);\n",
       "    var titlebar = this.root.find($('.ui-dialog-titlebar'));\n",
       "    titlebar.prepend(buttongrp);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._root_extra_style = function(el){\n",
       "    var fig = this\n",
       "    el.on(\"remove\", function(){\n",
       "\tfig.close_ws(fig, {});\n",
       "    });\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._canvas_extra_style = function(el){\n",
       "    // this is important to make the div 'focusable\n",
       "    el.attr('tabindex', 0)\n",
       "    // reach out to IPython and tell the keyboard manager to turn it's self\n",
       "    // off when our div gets focus\n",
       "\n",
       "    // location in version 3\n",
       "    if (IPython.notebook.keyboard_manager) {\n",
       "        IPython.notebook.keyboard_manager.register_events(el);\n",
       "    }\n",
       "    else {\n",
       "        // location in version 2\n",
       "        IPython.keyboard_manager.register_events(el);\n",
       "    }\n",
       "\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
       "    var manager = IPython.notebook.keyboard_manager;\n",
       "    if (!manager)\n",
       "        manager = IPython.keyboard_manager;\n",
       "\n",
       "    // Check for shift+enter\n",
       "    if (event.shiftKey && event.which == 13) {\n",
       "        this.canvas_div.blur();\n",
       "        event.shiftKey = false;\n",
       "        // Send a \"J\" for go to next cell\n",
       "        event.which = 74;\n",
       "        event.keyCode = 74;\n",
       "        manager.command_mode();\n",
       "        manager.handle_keydown(event);\n",
       "    }\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
       "    fig.ondownload(fig, null);\n",
       "}\n",
       "\n",
       "\n",
       "mpl.find_output_cell = function(html_output) {\n",
       "    // Return the cell and output element which can be found *uniquely* in the notebook.\n",
       "    // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n",
       "    // IPython event is triggered only after the cells have been serialised, which for\n",
       "    // our purposes (turning an active figure into a static one), is too late.\n",
       "    var cells = IPython.notebook.get_cells();\n",
       "    var ncells = cells.length;\n",
       "    for (var i=0; i<ncells; i++) {\n",
       "        var cell = cells[i];\n",
       "        if (cell.cell_type === 'code'){\n",
       "            for (var j=0; j<cell.output_area.outputs.length; j++) {\n",
       "                var data = cell.output_area.outputs[j];\n",
       "                if (data.data) {\n",
       "                    // IPython >= 3 moved mimebundle to data attribute of output\n",
       "                    data = data.data;\n",
       "                }\n",
       "                if (data['text/html'] == html_output) {\n",
       "                    return [cell, data, j];\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    }\n",
       "}\n",
       "\n",
       "// Register the function which deals with the matplotlib target/channel.\n",
       "// The kernel may be null if the page has been refreshed.\n",
       "if (IPython.notebook.kernel != null) {\n",
       "    IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n",
       "}\n"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<img src=\"\" width=\"400\">"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_____\n",
      "model: dense_fc \n",
      "\n",
      "mean best epoc: [18.66666667]\n",
      "mean training time: [86.19546501]\n",
      "STATS:\n",
      "acc           0.958680\n",
      "auc           0.988381\n",
      "loss          0.101426\n",
      "lr            0.000063\n",
      "recall        1.000000\n",
      "val_acc       0.907999\n",
      "val_auc       0.988512\n",
      "val_loss      0.669495\n",
      "val_recall    1.000000\n",
      "dtype: float64\n",
      "\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/javascript": [
       "/* Put everything inside the global mpl namespace */\n",
       "window.mpl = {};\n",
       "\n",
       "\n",
       "mpl.get_websocket_type = function() {\n",
       "    if (typeof(WebSocket) !== 'undefined') {\n",
       "        return WebSocket;\n",
       "    } else if (typeof(MozWebSocket) !== 'undefined') {\n",
       "        return MozWebSocket;\n",
       "    } else {\n",
       "        alert('Your browser does not have WebSocket support.' +\n",
       "              'Please try Chrome, Safari or Firefox ≥ 6. ' +\n",
       "              'Firefox 4 and 5 are also supported but you ' +\n",
       "              'have to enable WebSockets in about:config.');\n",
       "    };\n",
       "}\n",
       "\n",
       "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n",
       "    this.id = figure_id;\n",
       "\n",
       "    this.ws = websocket;\n",
       "\n",
       "    this.supports_binary = (this.ws.binaryType != undefined);\n",
       "\n",
       "    if (!this.supports_binary) {\n",
       "        var warnings = document.getElementById(\"mpl-warnings\");\n",
       "        if (warnings) {\n",
       "            warnings.style.display = 'block';\n",
       "            warnings.textContent = (\n",
       "                \"This browser does not support binary websocket messages. \" +\n",
       "                    \"Performance may be slow.\");\n",
       "        }\n",
       "    }\n",
       "\n",
       "    this.imageObj = new Image();\n",
       "\n",
       "    this.context = undefined;\n",
       "    this.message = undefined;\n",
       "    this.canvas = undefined;\n",
       "    this.rubberband_canvas = undefined;\n",
       "    this.rubberband_context = undefined;\n",
       "    this.format_dropdown = undefined;\n",
       "\n",
       "    this.image_mode = 'full';\n",
       "\n",
       "    this.root = $('<div/>');\n",
       "    this._root_extra_style(this.root)\n",
       "    this.root.attr('style', 'display: inline-block');\n",
       "\n",
       "    $(parent_element).append(this.root);\n",
       "\n",
       "    this._init_header(this);\n",
       "    this._init_canvas(this);\n",
       "    this._init_toolbar(this);\n",
       "\n",
       "    var fig = this;\n",
       "\n",
       "    this.waiting = false;\n",
       "\n",
       "    this.ws.onopen =  function () {\n",
       "            fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n",
       "            fig.send_message(\"send_image_mode\", {});\n",
       "            if (mpl.ratio != 1) {\n",
       "                fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n",
       "            }\n",
       "            fig.send_message(\"refresh\", {});\n",
       "        }\n",
       "\n",
       "    this.imageObj.onload = function() {\n",
       "            if (fig.image_mode == 'full') {\n",
       "                // Full images could contain transparency (where diff images\n",
       "                // almost always do), so we need to clear the canvas so that\n",
       "                // there is no ghosting.\n",
       "                fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n",
       "            }\n",
       "            fig.context.drawImage(fig.imageObj, 0, 0);\n",
       "        };\n",
       "\n",
       "    this.imageObj.onunload = function() {\n",
       "        fig.ws.close();\n",
       "    }\n",
       "\n",
       "    this.ws.onmessage = this._make_on_message_function(this);\n",
       "\n",
       "    this.ondownload = ondownload;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_header = function() {\n",
       "    var titlebar = $(\n",
       "        '<div class=\"ui-dialog-titlebar ui-widget-header ui-corner-all ' +\n",
       "        'ui-helper-clearfix\"/>');\n",
       "    var titletext = $(\n",
       "        '<div class=\"ui-dialog-title\" style=\"width: 100%; ' +\n",
       "        'text-align: center; padding: 3px;\"/>');\n",
       "    titlebar.append(titletext)\n",
       "    this.root.append(titlebar);\n",
       "    this.header = titletext[0];\n",
       "}\n",
       "\n",
       "\n",
       "\n",
       "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n",
       "\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n",
       "\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_canvas = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var canvas_div = $('<div/>');\n",
       "\n",
       "    canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n",
       "\n",
       "    function canvas_keyboard_event(event) {\n",
       "        return fig.key_event(event, event['data']);\n",
       "    }\n",
       "\n",
       "    canvas_div.keydown('key_press', canvas_keyboard_event);\n",
       "    canvas_div.keyup('key_release', canvas_keyboard_event);\n",
       "    this.canvas_div = canvas_div\n",
       "    this._canvas_extra_style(canvas_div)\n",
       "    this.root.append(canvas_div);\n",
       "\n",
       "    var canvas = $('<canvas/>');\n",
       "    canvas.addClass('mpl-canvas');\n",
       "    canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n",
       "\n",
       "    this.canvas = canvas[0];\n",
       "    this.context = canvas[0].getContext(\"2d\");\n",
       "\n",
       "    var backingStore = this.context.backingStorePixelRatio ||\n",
       "\tthis.context.webkitBackingStorePixelRatio ||\n",
       "\tthis.context.mozBackingStorePixelRatio ||\n",
       "\tthis.context.msBackingStorePixelRatio ||\n",
       "\tthis.context.oBackingStorePixelRatio ||\n",
       "\tthis.context.backingStorePixelRatio || 1;\n",
       "\n",
       "    mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n",
       "\n",
       "    var rubberband = $('<canvas/>');\n",
       "    rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n",
       "\n",
       "    var pass_mouse_events = true;\n",
       "\n",
       "    canvas_div.resizable({\n",
       "        start: function(event, ui) {\n",
       "            pass_mouse_events = false;\n",
       "        },\n",
       "        resize: function(event, ui) {\n",
       "            fig.request_resize(ui.size.width, ui.size.height);\n",
       "        },\n",
       "        stop: function(event, ui) {\n",
       "            pass_mouse_events = true;\n",
       "            fig.request_resize(ui.size.width, ui.size.height);\n",
       "        },\n",
       "    });\n",
       "\n",
       "    function mouse_event_fn(event) {\n",
       "        if (pass_mouse_events)\n",
       "            return fig.mouse_event(event, event['data']);\n",
       "    }\n",
       "\n",
       "    rubberband.mousedown('button_press', mouse_event_fn);\n",
       "    rubberband.mouseup('button_release', mouse_event_fn);\n",
       "    // Throttle sequential mouse events to 1 every 20ms.\n",
       "    rubberband.mousemove('motion_notify', mouse_event_fn);\n",
       "\n",
       "    rubberband.mouseenter('figure_enter', mouse_event_fn);\n",
       "    rubberband.mouseleave('figure_leave', mouse_event_fn);\n",
       "\n",
       "    canvas_div.on(\"wheel\", function (event) {\n",
       "        event = event.originalEvent;\n",
       "        event['data'] = 'scroll'\n",
       "        if (event.deltaY < 0) {\n",
       "            event.step = 1;\n",
       "        } else {\n",
       "            event.step = -1;\n",
       "        }\n",
       "        mouse_event_fn(event);\n",
       "    });\n",
       "\n",
       "    canvas_div.append(canvas);\n",
       "    canvas_div.append(rubberband);\n",
       "\n",
       "    this.rubberband = rubberband;\n",
       "    this.rubberband_canvas = rubberband[0];\n",
       "    this.rubberband_context = rubberband[0].getContext(\"2d\");\n",
       "    this.rubberband_context.strokeStyle = \"#000000\";\n",
       "\n",
       "    this._resize_canvas = function(width, height) {\n",
       "        // Keep the size of the canvas, canvas container, and rubber band\n",
       "        // canvas in synch.\n",
       "        canvas_div.css('width', width)\n",
       "        canvas_div.css('height', height)\n",
       "\n",
       "        canvas.attr('width', width * mpl.ratio);\n",
       "        canvas.attr('height', height * mpl.ratio);\n",
       "        canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n",
       "\n",
       "        rubberband.attr('width', width);\n",
       "        rubberband.attr('height', height);\n",
       "    }\n",
       "\n",
       "    // Set the figure to an initial 600x600px, this will subsequently be updated\n",
       "    // upon first draw.\n",
       "    this._resize_canvas(600, 600);\n",
       "\n",
       "    // Disable right mouse context menu.\n",
       "    $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n",
       "        return false;\n",
       "    });\n",
       "\n",
       "    function set_focus () {\n",
       "        canvas.focus();\n",
       "        canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    window.setTimeout(set_focus, 100);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_toolbar = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var nav_element = $('<div/>')\n",
       "    nav_element.attr('style', 'width: 100%');\n",
       "    this.root.append(nav_element);\n",
       "\n",
       "    // Define a callback function for later on.\n",
       "    function toolbar_event(event) {\n",
       "        return fig.toolbar_button_onclick(event['data']);\n",
       "    }\n",
       "    function toolbar_mouse_event(event) {\n",
       "        return fig.toolbar_button_onmouseover(event['data']);\n",
       "    }\n",
       "\n",
       "    for(var toolbar_ind in mpl.toolbar_items) {\n",
       "        var name = mpl.toolbar_items[toolbar_ind][0];\n",
       "        var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
       "        var image = mpl.toolbar_items[toolbar_ind][2];\n",
       "        var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
       "\n",
       "        if (!name) {\n",
       "            // put a spacer in here.\n",
       "            continue;\n",
       "        }\n",
       "        var button = $('<button/>');\n",
       "        button.addClass('ui-button ui-widget ui-state-default ui-corner-all ' +\n",
       "                        'ui-button-icon-only');\n",
       "        button.attr('role', 'button');\n",
       "        button.attr('aria-disabled', 'false');\n",
       "        button.click(method_name, toolbar_event);\n",
       "        button.mouseover(tooltip, toolbar_mouse_event);\n",
       "\n",
       "        var icon_img = $('<span/>');\n",
       "        icon_img.addClass('ui-button-icon-primary ui-icon');\n",
       "        icon_img.addClass(image);\n",
       "        icon_img.addClass('ui-corner-all');\n",
       "\n",
       "        var tooltip_span = $('<span/>');\n",
       "        tooltip_span.addClass('ui-button-text');\n",
       "        tooltip_span.html(tooltip);\n",
       "\n",
       "        button.append(icon_img);\n",
       "        button.append(tooltip_span);\n",
       "\n",
       "        nav_element.append(button);\n",
       "    }\n",
       "\n",
       "    var fmt_picker_span = $('<span/>');\n",
       "\n",
       "    var fmt_picker = $('<select/>');\n",
       "    fmt_picker.addClass('mpl-toolbar-option ui-widget ui-widget-content');\n",
       "    fmt_picker_span.append(fmt_picker);\n",
       "    nav_element.append(fmt_picker_span);\n",
       "    this.format_dropdown = fmt_picker[0];\n",
       "\n",
       "    for (var ind in mpl.extensions) {\n",
       "        var fmt = mpl.extensions[ind];\n",
       "        var option = $(\n",
       "            '<option/>', {selected: fmt === mpl.default_extension}).html(fmt);\n",
       "        fmt_picker.append(option)\n",
       "    }\n",
       "\n",
       "    // Add hover states to the ui-buttons\n",
       "    $( \".ui-button\" ).hover(\n",
       "        function() { $(this).addClass(\"ui-state-hover\");},\n",
       "        function() { $(this).removeClass(\"ui-state-hover\");}\n",
       "    );\n",
       "\n",
       "    var status_bar = $('<span class=\"mpl-message\"/>');\n",
       "    nav_element.append(status_bar);\n",
       "    this.message = status_bar[0];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.request_resize = function(x_pixels, y_pixels) {\n",
       "    // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n",
       "    // which will in turn request a refresh of the image.\n",
       "    this.send_message('resize', {'width': x_pixels, 'height': y_pixels});\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.send_message = function(type, properties) {\n",
       "    properties['type'] = type;\n",
       "    properties['figure_id'] = this.id;\n",
       "    this.ws.send(JSON.stringify(properties));\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.send_draw_message = function() {\n",
       "    if (!this.waiting) {\n",
       "        this.waiting = true;\n",
       "        this.ws.send(JSON.stringify({type: \"draw\", figure_id: this.id}));\n",
       "    }\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
       "    var format_dropdown = fig.format_dropdown;\n",
       "    var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n",
       "    fig.ondownload(fig, format);\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype.handle_resize = function(fig, msg) {\n",
       "    var size = msg['size'];\n",
       "    if (size[0] != fig.canvas.width || size[1] != fig.canvas.height) {\n",
       "        fig._resize_canvas(size[0], size[1]);\n",
       "        fig.send_message(\"refresh\", {});\n",
       "    };\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_rubberband = function(fig, msg) {\n",
       "    var x0 = msg['x0'] / mpl.ratio;\n",
       "    var y0 = (fig.canvas.height - msg['y0']) / mpl.ratio;\n",
       "    var x1 = msg['x1'] / mpl.ratio;\n",
       "    var y1 = (fig.canvas.height - msg['y1']) / mpl.ratio;\n",
       "    x0 = Math.floor(x0) + 0.5;\n",
       "    y0 = Math.floor(y0) + 0.5;\n",
       "    x1 = Math.floor(x1) + 0.5;\n",
       "    y1 = Math.floor(y1) + 0.5;\n",
       "    var min_x = Math.min(x0, x1);\n",
       "    var min_y = Math.min(y0, y1);\n",
       "    var width = Math.abs(x1 - x0);\n",
       "    var height = Math.abs(y1 - y0);\n",
       "\n",
       "    fig.rubberband_context.clearRect(\n",
       "        0, 0, fig.canvas.width, fig.canvas.height);\n",
       "\n",
       "    fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_figure_label = function(fig, msg) {\n",
       "    // Updates the figure title.\n",
       "    fig.header.textContent = msg['label'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_cursor = function(fig, msg) {\n",
       "    var cursor = msg['cursor'];\n",
       "    switch(cursor)\n",
       "    {\n",
       "    case 0:\n",
       "        cursor = 'pointer';\n",
       "        break;\n",
       "    case 1:\n",
       "        cursor = 'default';\n",
       "        break;\n",
       "    case 2:\n",
       "        cursor = 'crosshair';\n",
       "        break;\n",
       "    case 3:\n",
       "        cursor = 'move';\n",
       "        break;\n",
       "    }\n",
       "    fig.rubberband_canvas.style.cursor = cursor;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_message = function(fig, msg) {\n",
       "    fig.message.textContent = msg['message'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_draw = function(fig, msg) {\n",
       "    // Request the server to send over a new figure.\n",
       "    fig.send_draw_message();\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_image_mode = function(fig, msg) {\n",
       "    fig.image_mode = msg['mode'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.updated_canvas_event = function() {\n",
       "    // Called whenever the canvas gets updated.\n",
       "    this.send_message(\"ack\", {});\n",
       "}\n",
       "\n",
       "// A function to construct a web socket function for onmessage handling.\n",
       "// Called in the figure constructor.\n",
       "mpl.figure.prototype._make_on_message_function = function(fig) {\n",
       "    return function socket_on_message(evt) {\n",
       "        if (evt.data instanceof Blob) {\n",
       "            /* FIXME: We get \"Resource interpreted as Image but\n",
       "             * transferred with MIME type text/plain:\" errors on\n",
       "             * Chrome.  But how to set the MIME type?  It doesn't seem\n",
       "             * to be part of the websocket stream */\n",
       "            evt.data.type = \"image/png\";\n",
       "\n",
       "            /* Free the memory for the previous frames */\n",
       "            if (fig.imageObj.src) {\n",
       "                (window.URL || window.webkitURL).revokeObjectURL(\n",
       "                    fig.imageObj.src);\n",
       "            }\n",
       "\n",
       "            fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n",
       "                evt.data);\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        }\n",
       "        else if (typeof evt.data === 'string' && evt.data.slice(0, 21) == \"data:image/png;base64\") {\n",
       "            fig.imageObj.src = evt.data;\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        var msg = JSON.parse(evt.data);\n",
       "        var msg_type = msg['type'];\n",
       "\n",
       "        // Call the  \"handle_{type}\" callback, which takes\n",
       "        // the figure and JSON message as its only arguments.\n",
       "        try {\n",
       "            var callback = fig[\"handle_\" + msg_type];\n",
       "        } catch (e) {\n",
       "            console.log(\"No handler for the '\" + msg_type + \"' message type: \", msg);\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        if (callback) {\n",
       "            try {\n",
       "                // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n",
       "                callback(fig, msg);\n",
       "            } catch (e) {\n",
       "                console.log(\"Exception inside the 'handler_\" + msg_type + \"' callback:\", e, e.stack, msg);\n",
       "            }\n",
       "        }\n",
       "    };\n",
       "}\n",
       "\n",
       "// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas\n",
       "mpl.findpos = function(e) {\n",
       "    //this section is from http://www.quirksmode.org/js/events_properties.html\n",
       "    var targ;\n",
       "    if (!e)\n",
       "        e = window.event;\n",
       "    if (e.target)\n",
       "        targ = e.target;\n",
       "    else if (e.srcElement)\n",
       "        targ = e.srcElement;\n",
       "    if (targ.nodeType == 3) // defeat Safari bug\n",
       "        targ = targ.parentNode;\n",
       "\n",
       "    // jQuery normalizes the pageX and pageY\n",
       "    // pageX,Y are the mouse positions relative to the document\n",
       "    // offset() returns the position of the element relative to the document\n",
       "    var x = e.pageX - $(targ).offset().left;\n",
       "    var y = e.pageY - $(targ).offset().top;\n",
       "\n",
       "    return {\"x\": x, \"y\": y};\n",
       "};\n",
       "\n",
       "/*\n",
       " * return a copy of an object with only non-object keys\n",
       " * we need this to avoid circular references\n",
       " * http://stackoverflow.com/a/24161582/3208463\n",
       " */\n",
       "function simpleKeys (original) {\n",
       "  return Object.keys(original).reduce(function (obj, key) {\n",
       "    if (typeof original[key] !== 'object')\n",
       "        obj[key] = original[key]\n",
       "    return obj;\n",
       "  }, {});\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.mouse_event = function(event, name) {\n",
       "    var canvas_pos = mpl.findpos(event)\n",
       "\n",
       "    if (name === 'button_press')\n",
       "    {\n",
       "        this.canvas.focus();\n",
       "        this.canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    var x = canvas_pos.x * mpl.ratio;\n",
       "    var y = canvas_pos.y * mpl.ratio;\n",
       "\n",
       "    this.send_message(name, {x: x, y: y, button: event.button,\n",
       "                             step: event.step,\n",
       "                             guiEvent: simpleKeys(event)});\n",
       "\n",
       "    /* This prevents the web browser from automatically changing to\n",
       "     * the text insertion cursor when the button is pressed.  We want\n",
       "     * to control all of the cursor setting manually through the\n",
       "     * 'cursor' event from matplotlib */\n",
       "    event.preventDefault();\n",
       "    return false;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
       "    // Handle any extra behaviour associated with a key event\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.key_event = function(event, name) {\n",
       "\n",
       "    // Prevent repeat events\n",
       "    if (name == 'key_press')\n",
       "    {\n",
       "        if (event.which === this._key)\n",
       "            return;\n",
       "        else\n",
       "            this._key = event.which;\n",
       "    }\n",
       "    if (name == 'key_release')\n",
       "        this._key = null;\n",
       "\n",
       "    var value = '';\n",
       "    if (event.ctrlKey && event.which != 17)\n",
       "        value += \"ctrl+\";\n",
       "    if (event.altKey && event.which != 18)\n",
       "        value += \"alt+\";\n",
       "    if (event.shiftKey && event.which != 16)\n",
       "        value += \"shift+\";\n",
       "\n",
       "    value += 'k';\n",
       "    value += event.which.toString();\n",
       "\n",
       "    this._key_event_extra(event, name);\n",
       "\n",
       "    this.send_message(name, {key: value,\n",
       "                             guiEvent: simpleKeys(event)});\n",
       "    return false;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.toolbar_button_onclick = function(name) {\n",
       "    if (name == 'download') {\n",
       "        this.handle_save(this, null);\n",
       "    } else {\n",
       "        this.send_message(\"toolbar_button\", {name: name});\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.toolbar_button_onmouseover = function(tooltip) {\n",
       "    this.message.textContent = tooltip;\n",
       "};\n",
       "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Pan axes with left mouse, zoom with right\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n",
       "\n",
       "mpl.extensions = [\"eps\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\"];\n",
       "\n",
       "mpl.default_extension = \"png\";var comm_websocket_adapter = function(comm) {\n",
       "    // Create a \"websocket\"-like object which calls the given IPython comm\n",
       "    // object with the appropriate methods. Currently this is a non binary\n",
       "    // socket, so there is still some room for performance tuning.\n",
       "    var ws = {};\n",
       "\n",
       "    ws.close = function() {\n",
       "        comm.close()\n",
       "    };\n",
       "    ws.send = function(m) {\n",
       "        //console.log('sending', m);\n",
       "        comm.send(m);\n",
       "    };\n",
       "    // Register the callback with on_msg.\n",
       "    comm.on_msg(function(msg) {\n",
       "        //console.log('receiving', msg['content']['data'], msg);\n",
       "        // Pass the mpl event to the overridden (by mpl) onmessage function.\n",
       "        ws.onmessage(msg['content']['data'])\n",
       "    });\n",
       "    return ws;\n",
       "}\n",
       "\n",
       "mpl.mpl_figure_comm = function(comm, msg) {\n",
       "    // This is the function which gets called when the mpl process\n",
       "    // starts-up an IPython Comm through the \"matplotlib\" channel.\n",
       "\n",
       "    var id = msg.content.data.id;\n",
       "    // Get hold of the div created by the display call when the Comm\n",
       "    // socket was opened in Python.\n",
       "    var element = $(\"#\" + id);\n",
       "    var ws_proxy = comm_websocket_adapter(comm)\n",
       "\n",
       "    function ondownload(figure, format) {\n",
       "        window.open(figure.imageObj.src);\n",
       "    }\n",
       "\n",
       "    var fig = new mpl.figure(id, ws_proxy,\n",
       "                           ondownload,\n",
       "                           element.get(0));\n",
       "\n",
       "    // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n",
       "    // web socket which is closed, not our websocket->open comm proxy.\n",
       "    ws_proxy.onopen();\n",
       "\n",
       "    fig.parent_element = element.get(0);\n",
       "    fig.cell_info = mpl.find_output_cell(\"<div id='\" + id + \"'></div>\");\n",
       "    if (!fig.cell_info) {\n",
       "        console.error(\"Failed to find cell for figure\", id, fig);\n",
       "        return;\n",
       "    }\n",
       "\n",
       "    var output_index = fig.cell_info[2]\n",
       "    var cell = fig.cell_info[0];\n",
       "\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_close = function(fig, msg) {\n",
       "    var width = fig.canvas.width/mpl.ratio\n",
       "    fig.root.unbind('remove')\n",
       "\n",
       "    // Update the output cell to use the data from the current canvas.\n",
       "    fig.push_to_output();\n",
       "    var dataURL = fig.canvas.toDataURL();\n",
       "    // Re-enable the keyboard manager in IPython - without this line, in FF,\n",
       "    // the notebook keyboard shortcuts fail.\n",
       "    IPython.keyboard_manager.enable()\n",
       "    $(fig.parent_element).html('<img src=\"' + dataURL + '\" width=\"' + width + '\">');\n",
       "    fig.close_ws(fig, msg);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.close_ws = function(fig, msg){\n",
       "    fig.send_message('closing', msg);\n",
       "    // fig.ws.close()\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.push_to_output = function(remove_interactive) {\n",
       "    // Turn the data on the canvas into data in the output cell.\n",
       "    var width = this.canvas.width/mpl.ratio\n",
       "    var dataURL = this.canvas.toDataURL();\n",
       "    this.cell_info[1]['text/html'] = '<img src=\"' + dataURL + '\" width=\"' + width + '\">';\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.updated_canvas_event = function() {\n",
       "    // Tell IPython that the notebook contents must change.\n",
       "    IPython.notebook.set_dirty(true);\n",
       "    this.send_message(\"ack\", {});\n",
       "    var fig = this;\n",
       "    // Wait a second, then push the new image to the DOM so\n",
       "    // that it is saved nicely (might be nice to debounce this).\n",
       "    setTimeout(function () { fig.push_to_output() }, 1000);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_toolbar = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var nav_element = $('<div/>')\n",
       "    nav_element.attr('style', 'width: 100%');\n",
       "    this.root.append(nav_element);\n",
       "\n",
       "    // Define a callback function for later on.\n",
       "    function toolbar_event(event) {\n",
       "        return fig.toolbar_button_onclick(event['data']);\n",
       "    }\n",
       "    function toolbar_mouse_event(event) {\n",
       "        return fig.toolbar_button_onmouseover(event['data']);\n",
       "    }\n",
       "\n",
       "    for(var toolbar_ind in mpl.toolbar_items){\n",
       "        var name = mpl.toolbar_items[toolbar_ind][0];\n",
       "        var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
       "        var image = mpl.toolbar_items[toolbar_ind][2];\n",
       "        var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
       "\n",
       "        if (!name) { continue; };\n",
       "\n",
       "        var button = $('<button class=\"btn btn-default\" href=\"#\" title=\"' + name + '\"><i class=\"fa ' + image + ' fa-lg\"></i></button>');\n",
       "        button.click(method_name, toolbar_event);\n",
       "        button.mouseover(tooltip, toolbar_mouse_event);\n",
       "        nav_element.append(button);\n",
       "    }\n",
       "\n",
       "    // Add the status bar.\n",
       "    var status_bar = $('<span class=\"mpl-message\" style=\"text-align:right; float: right;\"/>');\n",
       "    nav_element.append(status_bar);\n",
       "    this.message = status_bar[0];\n",
       "\n",
       "    // Add the close button to the window.\n",
       "    var buttongrp = $('<div class=\"btn-group inline pull-right\"></div>');\n",
       "    var button = $('<button class=\"btn btn-mini btn-primary\" href=\"#\" title=\"Stop Interaction\"><i class=\"fa fa-power-off icon-remove icon-large\"></i></button>');\n",
       "    button.click(function (evt) { fig.handle_close(fig, {}); } );\n",
       "    button.mouseover('Stop Interaction', toolbar_mouse_event);\n",
       "    buttongrp.append(button);\n",
       "    var titlebar = this.root.find($('.ui-dialog-titlebar'));\n",
       "    titlebar.prepend(buttongrp);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._root_extra_style = function(el){\n",
       "    var fig = this\n",
       "    el.on(\"remove\", function(){\n",
       "\tfig.close_ws(fig, {});\n",
       "    });\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._canvas_extra_style = function(el){\n",
       "    // this is important to make the div 'focusable\n",
       "    el.attr('tabindex', 0)\n",
       "    // reach out to IPython and tell the keyboard manager to turn it's self\n",
       "    // off when our div gets focus\n",
       "\n",
       "    // location in version 3\n",
       "    if (IPython.notebook.keyboard_manager) {\n",
       "        IPython.notebook.keyboard_manager.register_events(el);\n",
       "    }\n",
       "    else {\n",
       "        // location in version 2\n",
       "        IPython.keyboard_manager.register_events(el);\n",
       "    }\n",
       "\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
       "    var manager = IPython.notebook.keyboard_manager;\n",
       "    if (!manager)\n",
       "        manager = IPython.keyboard_manager;\n",
       "\n",
       "    // Check for shift+enter\n",
       "    if (event.shiftKey && event.which == 13) {\n",
       "        this.canvas_div.blur();\n",
       "        event.shiftKey = false;\n",
       "        // Send a \"J\" for go to next cell\n",
       "        event.which = 74;\n",
       "        event.keyCode = 74;\n",
       "        manager.command_mode();\n",
       "        manager.handle_keydown(event);\n",
       "    }\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
       "    fig.ondownload(fig, null);\n",
       "}\n",
       "\n",
       "\n",
       "mpl.find_output_cell = function(html_output) {\n",
       "    // Return the cell and output element which can be found *uniquely* in the notebook.\n",
       "    // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n",
       "    // IPython event is triggered only after the cells have been serialised, which for\n",
       "    // our purposes (turning an active figure into a static one), is too late.\n",
       "    var cells = IPython.notebook.get_cells();\n",
       "    var ncells = cells.length;\n",
       "    for (var i=0; i<ncells; i++) {\n",
       "        var cell = cells[i];\n",
       "        if (cell.cell_type === 'code'){\n",
       "            for (var j=0; j<cell.output_area.outputs.length; j++) {\n",
       "                var data = cell.output_area.outputs[j];\n",
       "                if (data.data) {\n",
       "                    // IPython >= 3 moved mimebundle to data attribute of output\n",
       "                    data = data.data;\n",
       "                }\n",
       "                if (data['text/html'] == html_output) {\n",
       "                    return [cell, data, j];\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    }\n",
       "}\n",
       "\n",
       "// Register the function which deals with the matplotlib target/channel.\n",
       "// The kernel may be null if the page has been refreshed.\n",
       "if (IPython.notebook.kernel != null) {\n",
       "    IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n",
       "}\n"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<img src=\"\" width=\"400\">"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_____\n",
      "model: conv_1d \n",
      "\n",
      "mean best epoc: [15.]\n",
      "mean training time: [59.80732369]\n",
      "STATS:\n",
      "acc           0.964292\n",
      "auc           0.993495\n",
      "loss          0.074132\n",
      "lr            0.000125\n",
      "recall        1.000000\n",
      "val_acc       0.915024\n",
      "val_auc       0.993533\n",
      "val_loss      0.397048\n",
      "val_recall    1.000000\n",
      "dtype: float64\n",
      "\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/javascript": [
       "/* Put everything inside the global mpl namespace */\n",
       "window.mpl = {};\n",
       "\n",
       "\n",
       "mpl.get_websocket_type = function() {\n",
       "    if (typeof(WebSocket) !== 'undefined') {\n",
       "        return WebSocket;\n",
       "    } else if (typeof(MozWebSocket) !== 'undefined') {\n",
       "        return MozWebSocket;\n",
       "    } else {\n",
       "        alert('Your browser does not have WebSocket support.' +\n",
       "              'Please try Chrome, Safari or Firefox ≥ 6. ' +\n",
       "              'Firefox 4 and 5 are also supported but you ' +\n",
       "              'have to enable WebSockets in about:config.');\n",
       "    };\n",
       "}\n",
       "\n",
       "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n",
       "    this.id = figure_id;\n",
       "\n",
       "    this.ws = websocket;\n",
       "\n",
       "    this.supports_binary = (this.ws.binaryType != undefined);\n",
       "\n",
       "    if (!this.supports_binary) {\n",
       "        var warnings = document.getElementById(\"mpl-warnings\");\n",
       "        if (warnings) {\n",
       "            warnings.style.display = 'block';\n",
       "            warnings.textContent = (\n",
       "                \"This browser does not support binary websocket messages. \" +\n",
       "                    \"Performance may be slow.\");\n",
       "        }\n",
       "    }\n",
       "\n",
       "    this.imageObj = new Image();\n",
       "\n",
       "    this.context = undefined;\n",
       "    this.message = undefined;\n",
       "    this.canvas = undefined;\n",
       "    this.rubberband_canvas = undefined;\n",
       "    this.rubberband_context = undefined;\n",
       "    this.format_dropdown = undefined;\n",
       "\n",
       "    this.image_mode = 'full';\n",
       "\n",
       "    this.root = $('<div/>');\n",
       "    this._root_extra_style(this.root)\n",
       "    this.root.attr('style', 'display: inline-block');\n",
       "\n",
       "    $(parent_element).append(this.root);\n",
       "\n",
       "    this._init_header(this);\n",
       "    this._init_canvas(this);\n",
       "    this._init_toolbar(this);\n",
       "\n",
       "    var fig = this;\n",
       "\n",
       "    this.waiting = false;\n",
       "\n",
       "    this.ws.onopen =  function () {\n",
       "            fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n",
       "            fig.send_message(\"send_image_mode\", {});\n",
       "            if (mpl.ratio != 1) {\n",
       "                fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n",
       "            }\n",
       "            fig.send_message(\"refresh\", {});\n",
       "        }\n",
       "\n",
       "    this.imageObj.onload = function() {\n",
       "            if (fig.image_mode == 'full') {\n",
       "                // Full images could contain transparency (where diff images\n",
       "                // almost always do), so we need to clear the canvas so that\n",
       "                // there is no ghosting.\n",
       "                fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n",
       "            }\n",
       "            fig.context.drawImage(fig.imageObj, 0, 0);\n",
       "        };\n",
       "\n",
       "    this.imageObj.onunload = function() {\n",
       "        fig.ws.close();\n",
       "    }\n",
       "\n",
       "    this.ws.onmessage = this._make_on_message_function(this);\n",
       "\n",
       "    this.ondownload = ondownload;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_header = function() {\n",
       "    var titlebar = $(\n",
       "        '<div class=\"ui-dialog-titlebar ui-widget-header ui-corner-all ' +\n",
       "        'ui-helper-clearfix\"/>');\n",
       "    var titletext = $(\n",
       "        '<div class=\"ui-dialog-title\" style=\"width: 100%; ' +\n",
       "        'text-align: center; padding: 3px;\"/>');\n",
       "    titlebar.append(titletext)\n",
       "    this.root.append(titlebar);\n",
       "    this.header = titletext[0];\n",
       "}\n",
       "\n",
       "\n",
       "\n",
       "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n",
       "\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n",
       "\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_canvas = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var canvas_div = $('<div/>');\n",
       "\n",
       "    canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n",
       "\n",
       "    function canvas_keyboard_event(event) {\n",
       "        return fig.key_event(event, event['data']);\n",
       "    }\n",
       "\n",
       "    canvas_div.keydown('key_press', canvas_keyboard_event);\n",
       "    canvas_div.keyup('key_release', canvas_keyboard_event);\n",
       "    this.canvas_div = canvas_div\n",
       "    this._canvas_extra_style(canvas_div)\n",
       "    this.root.append(canvas_div);\n",
       "\n",
       "    var canvas = $('<canvas/>');\n",
       "    canvas.addClass('mpl-canvas');\n",
       "    canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n",
       "\n",
       "    this.canvas = canvas[0];\n",
       "    this.context = canvas[0].getContext(\"2d\");\n",
       "\n",
       "    var backingStore = this.context.backingStorePixelRatio ||\n",
       "\tthis.context.webkitBackingStorePixelRatio ||\n",
       "\tthis.context.mozBackingStorePixelRatio ||\n",
       "\tthis.context.msBackingStorePixelRatio ||\n",
       "\tthis.context.oBackingStorePixelRatio ||\n",
       "\tthis.context.backingStorePixelRatio || 1;\n",
       "\n",
       "    mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n",
       "\n",
       "    var rubberband = $('<canvas/>');\n",
       "    rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n",
       "\n",
       "    var pass_mouse_events = true;\n",
       "\n",
       "    canvas_div.resizable({\n",
       "        start: function(event, ui) {\n",
       "            pass_mouse_events = false;\n",
       "        },\n",
       "        resize: function(event, ui) {\n",
       "            fig.request_resize(ui.size.width, ui.size.height);\n",
       "        },\n",
       "        stop: function(event, ui) {\n",
       "            pass_mouse_events = true;\n",
       "            fig.request_resize(ui.size.width, ui.size.height);\n",
       "        },\n",
       "    });\n",
       "\n",
       "    function mouse_event_fn(event) {\n",
       "        if (pass_mouse_events)\n",
       "            return fig.mouse_event(event, event['data']);\n",
       "    }\n",
       "\n",
       "    rubberband.mousedown('button_press', mouse_event_fn);\n",
       "    rubberband.mouseup('button_release', mouse_event_fn);\n",
       "    // Throttle sequential mouse events to 1 every 20ms.\n",
       "    rubberband.mousemove('motion_notify', mouse_event_fn);\n",
       "\n",
       "    rubberband.mouseenter('figure_enter', mouse_event_fn);\n",
       "    rubberband.mouseleave('figure_leave', mouse_event_fn);\n",
       "\n",
       "    canvas_div.on(\"wheel\", function (event) {\n",
       "        event = event.originalEvent;\n",
       "        event['data'] = 'scroll'\n",
       "        if (event.deltaY < 0) {\n",
       "            event.step = 1;\n",
       "        } else {\n",
       "            event.step = -1;\n",
       "        }\n",
       "        mouse_event_fn(event);\n",
       "    });\n",
       "\n",
       "    canvas_div.append(canvas);\n",
       "    canvas_div.append(rubberband);\n",
       "\n",
       "    this.rubberband = rubberband;\n",
       "    this.rubberband_canvas = rubberband[0];\n",
       "    this.rubberband_context = rubberband[0].getContext(\"2d\");\n",
       "    this.rubberband_context.strokeStyle = \"#000000\";\n",
       "\n",
       "    this._resize_canvas = function(width, height) {\n",
       "        // Keep the size of the canvas, canvas container, and rubber band\n",
       "        // canvas in synch.\n",
       "        canvas_div.css('width', width)\n",
       "        canvas_div.css('height', height)\n",
       "\n",
       "        canvas.attr('width', width * mpl.ratio);\n",
       "        canvas.attr('height', height * mpl.ratio);\n",
       "        canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n",
       "\n",
       "        rubberband.attr('width', width);\n",
       "        rubberband.attr('height', height);\n",
       "    }\n",
       "\n",
       "    // Set the figure to an initial 600x600px, this will subsequently be updated\n",
       "    // upon first draw.\n",
       "    this._resize_canvas(600, 600);\n",
       "\n",
       "    // Disable right mouse context menu.\n",
       "    $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n",
       "        return false;\n",
       "    });\n",
       "\n",
       "    function set_focus () {\n",
       "        canvas.focus();\n",
       "        canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    window.setTimeout(set_focus, 100);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_toolbar = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var nav_element = $('<div/>')\n",
       "    nav_element.attr('style', 'width: 100%');\n",
       "    this.root.append(nav_element);\n",
       "\n",
       "    // Define a callback function for later on.\n",
       "    function toolbar_event(event) {\n",
       "        return fig.toolbar_button_onclick(event['data']);\n",
       "    }\n",
       "    function toolbar_mouse_event(event) {\n",
       "        return fig.toolbar_button_onmouseover(event['data']);\n",
       "    }\n",
       "\n",
       "    for(var toolbar_ind in mpl.toolbar_items) {\n",
       "        var name = mpl.toolbar_items[toolbar_ind][0];\n",
       "        var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
       "        var image = mpl.toolbar_items[toolbar_ind][2];\n",
       "        var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
       "\n",
       "        if (!name) {\n",
       "            // put a spacer in here.\n",
       "            continue;\n",
       "        }\n",
       "        var button = $('<button/>');\n",
       "        button.addClass('ui-button ui-widget ui-state-default ui-corner-all ' +\n",
       "                        'ui-button-icon-only');\n",
       "        button.attr('role', 'button');\n",
       "        button.attr('aria-disabled', 'false');\n",
       "        button.click(method_name, toolbar_event);\n",
       "        button.mouseover(tooltip, toolbar_mouse_event);\n",
       "\n",
       "        var icon_img = $('<span/>');\n",
       "        icon_img.addClass('ui-button-icon-primary ui-icon');\n",
       "        icon_img.addClass(image);\n",
       "        icon_img.addClass('ui-corner-all');\n",
       "\n",
       "        var tooltip_span = $('<span/>');\n",
       "        tooltip_span.addClass('ui-button-text');\n",
       "        tooltip_span.html(tooltip);\n",
       "\n",
       "        button.append(icon_img);\n",
       "        button.append(tooltip_span);\n",
       "\n",
       "        nav_element.append(button);\n",
       "    }\n",
       "\n",
       "    var fmt_picker_span = $('<span/>');\n",
       "\n",
       "    var fmt_picker = $('<select/>');\n",
       "    fmt_picker.addClass('mpl-toolbar-option ui-widget ui-widget-content');\n",
       "    fmt_picker_span.append(fmt_picker);\n",
       "    nav_element.append(fmt_picker_span);\n",
       "    this.format_dropdown = fmt_picker[0];\n",
       "\n",
       "    for (var ind in mpl.extensions) {\n",
       "        var fmt = mpl.extensions[ind];\n",
       "        var option = $(\n",
       "            '<option/>', {selected: fmt === mpl.default_extension}).html(fmt);\n",
       "        fmt_picker.append(option)\n",
       "    }\n",
       "\n",
       "    // Add hover states to the ui-buttons\n",
       "    $( \".ui-button\" ).hover(\n",
       "        function() { $(this).addClass(\"ui-state-hover\");},\n",
       "        function() { $(this).removeClass(\"ui-state-hover\");}\n",
       "    );\n",
       "\n",
       "    var status_bar = $('<span class=\"mpl-message\"/>');\n",
       "    nav_element.append(status_bar);\n",
       "    this.message = status_bar[0];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.request_resize = function(x_pixels, y_pixels) {\n",
       "    // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n",
       "    // which will in turn request a refresh of the image.\n",
       "    this.send_message('resize', {'width': x_pixels, 'height': y_pixels});\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.send_message = function(type, properties) {\n",
       "    properties['type'] = type;\n",
       "    properties['figure_id'] = this.id;\n",
       "    this.ws.send(JSON.stringify(properties));\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.send_draw_message = function() {\n",
       "    if (!this.waiting) {\n",
       "        this.waiting = true;\n",
       "        this.ws.send(JSON.stringify({type: \"draw\", figure_id: this.id}));\n",
       "    }\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
       "    var format_dropdown = fig.format_dropdown;\n",
       "    var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n",
       "    fig.ondownload(fig, format);\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype.handle_resize = function(fig, msg) {\n",
       "    var size = msg['size'];\n",
       "    if (size[0] != fig.canvas.width || size[1] != fig.canvas.height) {\n",
       "        fig._resize_canvas(size[0], size[1]);\n",
       "        fig.send_message(\"refresh\", {});\n",
       "    };\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_rubberband = function(fig, msg) {\n",
       "    var x0 = msg['x0'] / mpl.ratio;\n",
       "    var y0 = (fig.canvas.height - msg['y0']) / mpl.ratio;\n",
       "    var x1 = msg['x1'] / mpl.ratio;\n",
       "    var y1 = (fig.canvas.height - msg['y1']) / mpl.ratio;\n",
       "    x0 = Math.floor(x0) + 0.5;\n",
       "    y0 = Math.floor(y0) + 0.5;\n",
       "    x1 = Math.floor(x1) + 0.5;\n",
       "    y1 = Math.floor(y1) + 0.5;\n",
       "    var min_x = Math.min(x0, x1);\n",
       "    var min_y = Math.min(y0, y1);\n",
       "    var width = Math.abs(x1 - x0);\n",
       "    var height = Math.abs(y1 - y0);\n",
       "\n",
       "    fig.rubberband_context.clearRect(\n",
       "        0, 0, fig.canvas.width, fig.canvas.height);\n",
       "\n",
       "    fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_figure_label = function(fig, msg) {\n",
       "    // Updates the figure title.\n",
       "    fig.header.textContent = msg['label'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_cursor = function(fig, msg) {\n",
       "    var cursor = msg['cursor'];\n",
       "    switch(cursor)\n",
       "    {\n",
       "    case 0:\n",
       "        cursor = 'pointer';\n",
       "        break;\n",
       "    case 1:\n",
       "        cursor = 'default';\n",
       "        break;\n",
       "    case 2:\n",
       "        cursor = 'crosshair';\n",
       "        break;\n",
       "    case 3:\n",
       "        cursor = 'move';\n",
       "        break;\n",
       "    }\n",
       "    fig.rubberband_canvas.style.cursor = cursor;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_message = function(fig, msg) {\n",
       "    fig.message.textContent = msg['message'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_draw = function(fig, msg) {\n",
       "    // Request the server to send over a new figure.\n",
       "    fig.send_draw_message();\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_image_mode = function(fig, msg) {\n",
       "    fig.image_mode = msg['mode'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.updated_canvas_event = function() {\n",
       "    // Called whenever the canvas gets updated.\n",
       "    this.send_message(\"ack\", {});\n",
       "}\n",
       "\n",
       "// A function to construct a web socket function for onmessage handling.\n",
       "// Called in the figure constructor.\n",
       "mpl.figure.prototype._make_on_message_function = function(fig) {\n",
       "    return function socket_on_message(evt) {\n",
       "        if (evt.data instanceof Blob) {\n",
       "            /* FIXME: We get \"Resource interpreted as Image but\n",
       "             * transferred with MIME type text/plain:\" errors on\n",
       "             * Chrome.  But how to set the MIME type?  It doesn't seem\n",
       "             * to be part of the websocket stream */\n",
       "            evt.data.type = \"image/png\";\n",
       "\n",
       "            /* Free the memory for the previous frames */\n",
       "            if (fig.imageObj.src) {\n",
       "                (window.URL || window.webkitURL).revokeObjectURL(\n",
       "                    fig.imageObj.src);\n",
       "            }\n",
       "\n",
       "            fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n",
       "                evt.data);\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        }\n",
       "        else if (typeof evt.data === 'string' && evt.data.slice(0, 21) == \"data:image/png;base64\") {\n",
       "            fig.imageObj.src = evt.data;\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        var msg = JSON.parse(evt.data);\n",
       "        var msg_type = msg['type'];\n",
       "\n",
       "        // Call the  \"handle_{type}\" callback, which takes\n",
       "        // the figure and JSON message as its only arguments.\n",
       "        try {\n",
       "            var callback = fig[\"handle_\" + msg_type];\n",
       "        } catch (e) {\n",
       "            console.log(\"No handler for the '\" + msg_type + \"' message type: \", msg);\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        if (callback) {\n",
       "            try {\n",
       "                // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n",
       "                callback(fig, msg);\n",
       "            } catch (e) {\n",
       "                console.log(\"Exception inside the 'handler_\" + msg_type + \"' callback:\", e, e.stack, msg);\n",
       "            }\n",
       "        }\n",
       "    };\n",
       "}\n",
       "\n",
       "// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas\n",
       "mpl.findpos = function(e) {\n",
       "    //this section is from http://www.quirksmode.org/js/events_properties.html\n",
       "    var targ;\n",
       "    if (!e)\n",
       "        e = window.event;\n",
       "    if (e.target)\n",
       "        targ = e.target;\n",
       "    else if (e.srcElement)\n",
       "        targ = e.srcElement;\n",
       "    if (targ.nodeType == 3) // defeat Safari bug\n",
       "        targ = targ.parentNode;\n",
       "\n",
       "    // jQuery normalizes the pageX and pageY\n",
       "    // pageX,Y are the mouse positions relative to the document\n",
       "    // offset() returns the position of the element relative to the document\n",
       "    var x = e.pageX - $(targ).offset().left;\n",
       "    var y = e.pageY - $(targ).offset().top;\n",
       "\n",
       "    return {\"x\": x, \"y\": y};\n",
       "};\n",
       "\n",
       "/*\n",
       " * return a copy of an object with only non-object keys\n",
       " * we need this to avoid circular references\n",
       " * http://stackoverflow.com/a/24161582/3208463\n",
       " */\n",
       "function simpleKeys (original) {\n",
       "  return Object.keys(original).reduce(function (obj, key) {\n",
       "    if (typeof original[key] !== 'object')\n",
       "        obj[key] = original[key]\n",
       "    return obj;\n",
       "  }, {});\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.mouse_event = function(event, name) {\n",
       "    var canvas_pos = mpl.findpos(event)\n",
       "\n",
       "    if (name === 'button_press')\n",
       "    {\n",
       "        this.canvas.focus();\n",
       "        this.canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    var x = canvas_pos.x * mpl.ratio;\n",
       "    var y = canvas_pos.y * mpl.ratio;\n",
       "\n",
       "    this.send_message(name, {x: x, y: y, button: event.button,\n",
       "                             step: event.step,\n",
       "                             guiEvent: simpleKeys(event)});\n",
       "\n",
       "    /* This prevents the web browser from automatically changing to\n",
       "     * the text insertion cursor when the button is pressed.  We want\n",
       "     * to control all of the cursor setting manually through the\n",
       "     * 'cursor' event from matplotlib */\n",
       "    event.preventDefault();\n",
       "    return false;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
       "    // Handle any extra behaviour associated with a key event\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.key_event = function(event, name) {\n",
       "\n",
       "    // Prevent repeat events\n",
       "    if (name == 'key_press')\n",
       "    {\n",
       "        if (event.which === this._key)\n",
       "            return;\n",
       "        else\n",
       "            this._key = event.which;\n",
       "    }\n",
       "    if (name == 'key_release')\n",
       "        this._key = null;\n",
       "\n",
       "    var value = '';\n",
       "    if (event.ctrlKey && event.which != 17)\n",
       "        value += \"ctrl+\";\n",
       "    if (event.altKey && event.which != 18)\n",
       "        value += \"alt+\";\n",
       "    if (event.shiftKey && event.which != 16)\n",
       "        value += \"shift+\";\n",
       "\n",
       "    value += 'k';\n",
       "    value += event.which.toString();\n",
       "\n",
       "    this._key_event_extra(event, name);\n",
       "\n",
       "    this.send_message(name, {key: value,\n",
       "                             guiEvent: simpleKeys(event)});\n",
       "    return false;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.toolbar_button_onclick = function(name) {\n",
       "    if (name == 'download') {\n",
       "        this.handle_save(this, null);\n",
       "    } else {\n",
       "        this.send_message(\"toolbar_button\", {name: name});\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.toolbar_button_onmouseover = function(tooltip) {\n",
       "    this.message.textContent = tooltip;\n",
       "};\n",
       "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Pan axes with left mouse, zoom with right\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n",
       "\n",
       "mpl.extensions = [\"eps\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\"];\n",
       "\n",
       "mpl.default_extension = \"png\";var comm_websocket_adapter = function(comm) {\n",
       "    // Create a \"websocket\"-like object which calls the given IPython comm\n",
       "    // object with the appropriate methods. Currently this is a non binary\n",
       "    // socket, so there is still some room for performance tuning.\n",
       "    var ws = {};\n",
       "\n",
       "    ws.close = function() {\n",
       "        comm.close()\n",
       "    };\n",
       "    ws.send = function(m) {\n",
       "        //console.log('sending', m);\n",
       "        comm.send(m);\n",
       "    };\n",
       "    // Register the callback with on_msg.\n",
       "    comm.on_msg(function(msg) {\n",
       "        //console.log('receiving', msg['content']['data'], msg);\n",
       "        // Pass the mpl event to the overridden (by mpl) onmessage function.\n",
       "        ws.onmessage(msg['content']['data'])\n",
       "    });\n",
       "    return ws;\n",
       "}\n",
       "\n",
       "mpl.mpl_figure_comm = function(comm, msg) {\n",
       "    // This is the function which gets called when the mpl process\n",
       "    // starts-up an IPython Comm through the \"matplotlib\" channel.\n",
       "\n",
       "    var id = msg.content.data.id;\n",
       "    // Get hold of the div created by the display call when the Comm\n",
       "    // socket was opened in Python.\n",
       "    var element = $(\"#\" + id);\n",
       "    var ws_proxy = comm_websocket_adapter(comm)\n",
       "\n",
       "    function ondownload(figure, format) {\n",
       "        window.open(figure.imageObj.src);\n",
       "    }\n",
       "\n",
       "    var fig = new mpl.figure(id, ws_proxy,\n",
       "                           ondownload,\n",
       "                           element.get(0));\n",
       "\n",
       "    // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n",
       "    // web socket which is closed, not our websocket->open comm proxy.\n",
       "    ws_proxy.onopen();\n",
       "\n",
       "    fig.parent_element = element.get(0);\n",
       "    fig.cell_info = mpl.find_output_cell(\"<div id='\" + id + \"'></div>\");\n",
       "    if (!fig.cell_info) {\n",
       "        console.error(\"Failed to find cell for figure\", id, fig);\n",
       "        return;\n",
       "    }\n",
       "\n",
       "    var output_index = fig.cell_info[2]\n",
       "    var cell = fig.cell_info[0];\n",
       "\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_close = function(fig, msg) {\n",
       "    var width = fig.canvas.width/mpl.ratio\n",
       "    fig.root.unbind('remove')\n",
       "\n",
       "    // Update the output cell to use the data from the current canvas.\n",
       "    fig.push_to_output();\n",
       "    var dataURL = fig.canvas.toDataURL();\n",
       "    // Re-enable the keyboard manager in IPython - without this line, in FF,\n",
       "    // the notebook keyboard shortcuts fail.\n",
       "    IPython.keyboard_manager.enable()\n",
       "    $(fig.parent_element).html('<img src=\"' + dataURL + '\" width=\"' + width + '\">');\n",
       "    fig.close_ws(fig, msg);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.close_ws = function(fig, msg){\n",
       "    fig.send_message('closing', msg);\n",
       "    // fig.ws.close()\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.push_to_output = function(remove_interactive) {\n",
       "    // Turn the data on the canvas into data in the output cell.\n",
       "    var width = this.canvas.width/mpl.ratio\n",
       "    var dataURL = this.canvas.toDataURL();\n",
       "    this.cell_info[1]['text/html'] = '<img src=\"' + dataURL + '\" width=\"' + width + '\">';\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.updated_canvas_event = function() {\n",
       "    // Tell IPython that the notebook contents must change.\n",
       "    IPython.notebook.set_dirty(true);\n",
       "    this.send_message(\"ack\", {});\n",
       "    var fig = this;\n",
       "    // Wait a second, then push the new image to the DOM so\n",
       "    // that it is saved nicely (might be nice to debounce this).\n",
       "    setTimeout(function () { fig.push_to_output() }, 1000);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_toolbar = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var nav_element = $('<div/>')\n",
       "    nav_element.attr('style', 'width: 100%');\n",
       "    this.root.append(nav_element);\n",
       "\n",
       "    // Define a callback function for later on.\n",
       "    function toolbar_event(event) {\n",
       "        return fig.toolbar_button_onclick(event['data']);\n",
       "    }\n",
       "    function toolbar_mouse_event(event) {\n",
       "        return fig.toolbar_button_onmouseover(event['data']);\n",
       "    }\n",
       "\n",
       "    for(var toolbar_ind in mpl.toolbar_items){\n",
       "        var name = mpl.toolbar_items[toolbar_ind][0];\n",
       "        var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
       "        var image = mpl.toolbar_items[toolbar_ind][2];\n",
       "        var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
       "\n",
       "        if (!name) { continue; };\n",
       "\n",
       "        var button = $('<button class=\"btn btn-default\" href=\"#\" title=\"' + name + '\"><i class=\"fa ' + image + ' fa-lg\"></i></button>');\n",
       "        button.click(method_name, toolbar_event);\n",
       "        button.mouseover(tooltip, toolbar_mouse_event);\n",
       "        nav_element.append(button);\n",
       "    }\n",
       "\n",
       "    // Add the status bar.\n",
       "    var status_bar = $('<span class=\"mpl-message\" style=\"text-align:right; float: right;\"/>');\n",
       "    nav_element.append(status_bar);\n",
       "    this.message = status_bar[0];\n",
       "\n",
       "    // Add the close button to the window.\n",
       "    var buttongrp = $('<div class=\"btn-group inline pull-right\"></div>');\n",
       "    var button = $('<button class=\"btn btn-mini btn-primary\" href=\"#\" title=\"Stop Interaction\"><i class=\"fa fa-power-off icon-remove icon-large\"></i></button>');\n",
       "    button.click(function (evt) { fig.handle_close(fig, {}); } );\n",
       "    button.mouseover('Stop Interaction', toolbar_mouse_event);\n",
       "    buttongrp.append(button);\n",
       "    var titlebar = this.root.find($('.ui-dialog-titlebar'));\n",
       "    titlebar.prepend(buttongrp);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._root_extra_style = function(el){\n",
       "    var fig = this\n",
       "    el.on(\"remove\", function(){\n",
       "\tfig.close_ws(fig, {});\n",
       "    });\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._canvas_extra_style = function(el){\n",
       "    // this is important to make the div 'focusable\n",
       "    el.attr('tabindex', 0)\n",
       "    // reach out to IPython and tell the keyboard manager to turn it's self\n",
       "    // off when our div gets focus\n",
       "\n",
       "    // location in version 3\n",
       "    if (IPython.notebook.keyboard_manager) {\n",
       "        IPython.notebook.keyboard_manager.register_events(el);\n",
       "    }\n",
       "    else {\n",
       "        // location in version 2\n",
       "        IPython.keyboard_manager.register_events(el);\n",
       "    }\n",
       "\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
       "    var manager = IPython.notebook.keyboard_manager;\n",
       "    if (!manager)\n",
       "        manager = IPython.keyboard_manager;\n",
       "\n",
       "    // Check for shift+enter\n",
       "    if (event.shiftKey && event.which == 13) {\n",
       "        this.canvas_div.blur();\n",
       "        event.shiftKey = false;\n",
       "        // Send a \"J\" for go to next cell\n",
       "        event.which = 74;\n",
       "        event.keyCode = 74;\n",
       "        manager.command_mode();\n",
       "        manager.handle_keydown(event);\n",
       "    }\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
       "    fig.ondownload(fig, null);\n",
       "}\n",
       "\n",
       "\n",
       "mpl.find_output_cell = function(html_output) {\n",
       "    // Return the cell and output element which can be found *uniquely* in the notebook.\n",
       "    // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n",
       "    // IPython event is triggered only after the cells have been serialised, which for\n",
       "    // our purposes (turning an active figure into a static one), is too late.\n",
       "    var cells = IPython.notebook.get_cells();\n",
       "    var ncells = cells.length;\n",
       "    for (var i=0; i<ncells; i++) {\n",
       "        var cell = cells[i];\n",
       "        if (cell.cell_type === 'code'){\n",
       "            for (var j=0; j<cell.output_area.outputs.length; j++) {\n",
       "                var data = cell.output_area.outputs[j];\n",
       "                if (data.data) {\n",
       "                    // IPython >= 3 moved mimebundle to data attribute of output\n",
       "                    data = data.data;\n",
       "                }\n",
       "                if (data['text/html'] == html_output) {\n",
       "                    return [cell, data, j];\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    }\n",
       "}\n",
       "\n",
       "// Register the function which deals with the matplotlib target/channel.\n",
       "// The kernel may be null if the page has been refreshed.\n",
       "if (IPython.notebook.kernel != null) {\n",
       "    IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n",
       "}\n"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<img src=\"\" width=\"400\">"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "for model_name in trainig_reulsts.keys():\n",
    "    print('_____')\n",
    "    print('model: {} \\n'.format(model_name))\n",
    "    print('mean best epoc: {}'.format(trainig_reulsts[model_name]['stats_best_epoch'].values))\n",
    "    print('mean training time: {}'.format(trainig_reulsts[model_name]['stats_time_takes'].values))\n",
    "    \n",
    "    print('STATS:')\n",
    "    \n",
    "    print(trainig_reulsts[model_name]['stats_best_stats'])\n",
    "    print('\\n')\n",
    "\n",
    "    plt.figure(figsize = (4,4))\n",
    "    stats_for_model = trainig_reulsts[model_name]['trained_models_stats']\n",
    "    stats_for_model[stats_for_model.columns[stats_for_model.columns.str.contains(pat = 'val')]].boxplot()\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.9927354 , 0.99437265, 0.99348999])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stats_for_model[['val_auc']].values.ravel()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "/* Put everything inside the global mpl namespace */\n",
       "window.mpl = {};\n",
       "\n",
       "\n",
       "mpl.get_websocket_type = function() {\n",
       "    if (typeof(WebSocket) !== 'undefined') {\n",
       "        return WebSocket;\n",
       "    } else if (typeof(MozWebSocket) !== 'undefined') {\n",
       "        return MozWebSocket;\n",
       "    } else {\n",
       "        alert('Your browser does not have WebSocket support.' +\n",
       "              'Please try Chrome, Safari or Firefox ≥ 6. ' +\n",
       "              'Firefox 4 and 5 are also supported but you ' +\n",
       "              'have to enable WebSockets in about:config.');\n",
       "    };\n",
       "}\n",
       "\n",
       "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n",
       "    this.id = figure_id;\n",
       "\n",
       "    this.ws = websocket;\n",
       "\n",
       "    this.supports_binary = (this.ws.binaryType != undefined);\n",
       "\n",
       "    if (!this.supports_binary) {\n",
       "        var warnings = document.getElementById(\"mpl-warnings\");\n",
       "        if (warnings) {\n",
       "            warnings.style.display = 'block';\n",
       "            warnings.textContent = (\n",
       "                \"This browser does not support binary websocket messages. \" +\n",
       "                    \"Performance may be slow.\");\n",
       "        }\n",
       "    }\n",
       "\n",
       "    this.imageObj = new Image();\n",
       "\n",
       "    this.context = undefined;\n",
       "    this.message = undefined;\n",
       "    this.canvas = undefined;\n",
       "    this.rubberband_canvas = undefined;\n",
       "    this.rubberband_context = undefined;\n",
       "    this.format_dropdown = undefined;\n",
       "\n",
       "    this.image_mode = 'full';\n",
       "\n",
       "    this.root = $('<div/>');\n",
       "    this._root_extra_style(this.root)\n",
       "    this.root.attr('style', 'display: inline-block');\n",
       "\n",
       "    $(parent_element).append(this.root);\n",
       "\n",
       "    this._init_header(this);\n",
       "    this._init_canvas(this);\n",
       "    this._init_toolbar(this);\n",
       "\n",
       "    var fig = this;\n",
       "\n",
       "    this.waiting = false;\n",
       "\n",
       "    this.ws.onopen =  function () {\n",
       "            fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n",
       "            fig.send_message(\"send_image_mode\", {});\n",
       "            if (mpl.ratio != 1) {\n",
       "                fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n",
       "            }\n",
       "            fig.send_message(\"refresh\", {});\n",
       "        }\n",
       "\n",
       "    this.imageObj.onload = function() {\n",
       "            if (fig.image_mode == 'full') {\n",
       "                // Full images could contain transparency (where diff images\n",
       "                // almost always do), so we need to clear the canvas so that\n",
       "                // there is no ghosting.\n",
       "                fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n",
       "            }\n",
       "            fig.context.drawImage(fig.imageObj, 0, 0);\n",
       "        };\n",
       "\n",
       "    this.imageObj.onunload = function() {\n",
       "        fig.ws.close();\n",
       "    }\n",
       "\n",
       "    this.ws.onmessage = this._make_on_message_function(this);\n",
       "\n",
       "    this.ondownload = ondownload;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_header = function() {\n",
       "    var titlebar = $(\n",
       "        '<div class=\"ui-dialog-titlebar ui-widget-header ui-corner-all ' +\n",
       "        'ui-helper-clearfix\"/>');\n",
       "    var titletext = $(\n",
       "        '<div class=\"ui-dialog-title\" style=\"width: 100%; ' +\n",
       "        'text-align: center; padding: 3px;\"/>');\n",
       "    titlebar.append(titletext)\n",
       "    this.root.append(titlebar);\n",
       "    this.header = titletext[0];\n",
       "}\n",
       "\n",
       "\n",
       "\n",
       "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n",
       "\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n",
       "\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_canvas = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var canvas_div = $('<div/>');\n",
       "\n",
       "    canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n",
       "\n",
       "    function canvas_keyboard_event(event) {\n",
       "        return fig.key_event(event, event['data']);\n",
       "    }\n",
       "\n",
       "    canvas_div.keydown('key_press', canvas_keyboard_event);\n",
       "    canvas_div.keyup('key_release', canvas_keyboard_event);\n",
       "    this.canvas_div = canvas_div\n",
       "    this._canvas_extra_style(canvas_div)\n",
       "    this.root.append(canvas_div);\n",
       "\n",
       "    var canvas = $('<canvas/>');\n",
       "    canvas.addClass('mpl-canvas');\n",
       "    canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n",
       "\n",
       "    this.canvas = canvas[0];\n",
       "    this.context = canvas[0].getContext(\"2d\");\n",
       "\n",
       "    var backingStore = this.context.backingStorePixelRatio ||\n",
       "\tthis.context.webkitBackingStorePixelRatio ||\n",
       "\tthis.context.mozBackingStorePixelRatio ||\n",
       "\tthis.context.msBackingStorePixelRatio ||\n",
       "\tthis.context.oBackingStorePixelRatio ||\n",
       "\tthis.context.backingStorePixelRatio || 1;\n",
       "\n",
       "    mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n",
       "\n",
       "    var rubberband = $('<canvas/>');\n",
       "    rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n",
       "\n",
       "    var pass_mouse_events = true;\n",
       "\n",
       "    canvas_div.resizable({\n",
       "        start: function(event, ui) {\n",
       "            pass_mouse_events = false;\n",
       "        },\n",
       "        resize: function(event, ui) {\n",
       "            fig.request_resize(ui.size.width, ui.size.height);\n",
       "        },\n",
       "        stop: function(event, ui) {\n",
       "            pass_mouse_events = true;\n",
       "            fig.request_resize(ui.size.width, ui.size.height);\n",
       "        },\n",
       "    });\n",
       "\n",
       "    function mouse_event_fn(event) {\n",
       "        if (pass_mouse_events)\n",
       "            return fig.mouse_event(event, event['data']);\n",
       "    }\n",
       "\n",
       "    rubberband.mousedown('button_press', mouse_event_fn);\n",
       "    rubberband.mouseup('button_release', mouse_event_fn);\n",
       "    // Throttle sequential mouse events to 1 every 20ms.\n",
       "    rubberband.mousemove('motion_notify', mouse_event_fn);\n",
       "\n",
       "    rubberband.mouseenter('figure_enter', mouse_event_fn);\n",
       "    rubberband.mouseleave('figure_leave', mouse_event_fn);\n",
       "\n",
       "    canvas_div.on(\"wheel\", function (event) {\n",
       "        event = event.originalEvent;\n",
       "        event['data'] = 'scroll'\n",
       "        if (event.deltaY < 0) {\n",
       "            event.step = 1;\n",
       "        } else {\n",
       "            event.step = -1;\n",
       "        }\n",
       "        mouse_event_fn(event);\n",
       "    });\n",
       "\n",
       "    canvas_div.append(canvas);\n",
       "    canvas_div.append(rubberband);\n",
       "\n",
       "    this.rubberband = rubberband;\n",
       "    this.rubberband_canvas = rubberband[0];\n",
       "    this.rubberband_context = rubberband[0].getContext(\"2d\");\n",
       "    this.rubberband_context.strokeStyle = \"#000000\";\n",
       "\n",
       "    this._resize_canvas = function(width, height) {\n",
       "        // Keep the size of the canvas, canvas container, and rubber band\n",
       "        // canvas in synch.\n",
       "        canvas_div.css('width', width)\n",
       "        canvas_div.css('height', height)\n",
       "\n",
       "        canvas.attr('width', width * mpl.ratio);\n",
       "        canvas.attr('height', height * mpl.ratio);\n",
       "        canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n",
       "\n",
       "        rubberband.attr('width', width);\n",
       "        rubberband.attr('height', height);\n",
       "    }\n",
       "\n",
       "    // Set the figure to an initial 600x600px, this will subsequently be updated\n",
       "    // upon first draw.\n",
       "    this._resize_canvas(600, 600);\n",
       "\n",
       "    // Disable right mouse context menu.\n",
       "    $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n",
       "        return false;\n",
       "    });\n",
       "\n",
       "    function set_focus () {\n",
       "        canvas.focus();\n",
       "        canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    window.setTimeout(set_focus, 100);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_toolbar = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var nav_element = $('<div/>')\n",
       "    nav_element.attr('style', 'width: 100%');\n",
       "    this.root.append(nav_element);\n",
       "\n",
       "    // Define a callback function for later on.\n",
       "    function toolbar_event(event) {\n",
       "        return fig.toolbar_button_onclick(event['data']);\n",
       "    }\n",
       "    function toolbar_mouse_event(event) {\n",
       "        return fig.toolbar_button_onmouseover(event['data']);\n",
       "    }\n",
       "\n",
       "    for(var toolbar_ind in mpl.toolbar_items) {\n",
       "        var name = mpl.toolbar_items[toolbar_ind][0];\n",
       "        var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
       "        var image = mpl.toolbar_items[toolbar_ind][2];\n",
       "        var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
       "\n",
       "        if (!name) {\n",
       "            // put a spacer in here.\n",
       "            continue;\n",
       "        }\n",
       "        var button = $('<button/>');\n",
       "        button.addClass('ui-button ui-widget ui-state-default ui-corner-all ' +\n",
       "                        'ui-button-icon-only');\n",
       "        button.attr('role', 'button');\n",
       "        button.attr('aria-disabled', 'false');\n",
       "        button.click(method_name, toolbar_event);\n",
       "        button.mouseover(tooltip, toolbar_mouse_event);\n",
       "\n",
       "        var icon_img = $('<span/>');\n",
       "        icon_img.addClass('ui-button-icon-primary ui-icon');\n",
       "        icon_img.addClass(image);\n",
       "        icon_img.addClass('ui-corner-all');\n",
       "\n",
       "        var tooltip_span = $('<span/>');\n",
       "        tooltip_span.addClass('ui-button-text');\n",
       "        tooltip_span.html(tooltip);\n",
       "\n",
       "        button.append(icon_img);\n",
       "        button.append(tooltip_span);\n",
       "\n",
       "        nav_element.append(button);\n",
       "    }\n",
       "\n",
       "    var fmt_picker_span = $('<span/>');\n",
       "\n",
       "    var fmt_picker = $('<select/>');\n",
       "    fmt_picker.addClass('mpl-toolbar-option ui-widget ui-widget-content');\n",
       "    fmt_picker_span.append(fmt_picker);\n",
       "    nav_element.append(fmt_picker_span);\n",
       "    this.format_dropdown = fmt_picker[0];\n",
       "\n",
       "    for (var ind in mpl.extensions) {\n",
       "        var fmt = mpl.extensions[ind];\n",
       "        var option = $(\n",
       "            '<option/>', {selected: fmt === mpl.default_extension}).html(fmt);\n",
       "        fmt_picker.append(option)\n",
       "    }\n",
       "\n",
       "    // Add hover states to the ui-buttons\n",
       "    $( \".ui-button\" ).hover(\n",
       "        function() { $(this).addClass(\"ui-state-hover\");},\n",
       "        function() { $(this).removeClass(\"ui-state-hover\");}\n",
       "    );\n",
       "\n",
       "    var status_bar = $('<span class=\"mpl-message\"/>');\n",
       "    nav_element.append(status_bar);\n",
       "    this.message = status_bar[0];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.request_resize = function(x_pixels, y_pixels) {\n",
       "    // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n",
       "    // which will in turn request a refresh of the image.\n",
       "    this.send_message('resize', {'width': x_pixels, 'height': y_pixels});\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.send_message = function(type, properties) {\n",
       "    properties['type'] = type;\n",
       "    properties['figure_id'] = this.id;\n",
       "    this.ws.send(JSON.stringify(properties));\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.send_draw_message = function() {\n",
       "    if (!this.waiting) {\n",
       "        this.waiting = true;\n",
       "        this.ws.send(JSON.stringify({type: \"draw\", figure_id: this.id}));\n",
       "    }\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
       "    var format_dropdown = fig.format_dropdown;\n",
       "    var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n",
       "    fig.ondownload(fig, format);\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype.handle_resize = function(fig, msg) {\n",
       "    var size = msg['size'];\n",
       "    if (size[0] != fig.canvas.width || size[1] != fig.canvas.height) {\n",
       "        fig._resize_canvas(size[0], size[1]);\n",
       "        fig.send_message(\"refresh\", {});\n",
       "    };\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_rubberband = function(fig, msg) {\n",
       "    var x0 = msg['x0'] / mpl.ratio;\n",
       "    var y0 = (fig.canvas.height - msg['y0']) / mpl.ratio;\n",
       "    var x1 = msg['x1'] / mpl.ratio;\n",
       "    var y1 = (fig.canvas.height - msg['y1']) / mpl.ratio;\n",
       "    x0 = Math.floor(x0) + 0.5;\n",
       "    y0 = Math.floor(y0) + 0.5;\n",
       "    x1 = Math.floor(x1) + 0.5;\n",
       "    y1 = Math.floor(y1) + 0.5;\n",
       "    var min_x = Math.min(x0, x1);\n",
       "    var min_y = Math.min(y0, y1);\n",
       "    var width = Math.abs(x1 - x0);\n",
       "    var height = Math.abs(y1 - y0);\n",
       "\n",
       "    fig.rubberband_context.clearRect(\n",
       "        0, 0, fig.canvas.width, fig.canvas.height);\n",
       "\n",
       "    fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_figure_label = function(fig, msg) {\n",
       "    // Updates the figure title.\n",
       "    fig.header.textContent = msg['label'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_cursor = function(fig, msg) {\n",
       "    var cursor = msg['cursor'];\n",
       "    switch(cursor)\n",
       "    {\n",
       "    case 0:\n",
       "        cursor = 'pointer';\n",
       "        break;\n",
       "    case 1:\n",
       "        cursor = 'default';\n",
       "        break;\n",
       "    case 2:\n",
       "        cursor = 'crosshair';\n",
       "        break;\n",
       "    case 3:\n",
       "        cursor = 'move';\n",
       "        break;\n",
       "    }\n",
       "    fig.rubberband_canvas.style.cursor = cursor;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_message = function(fig, msg) {\n",
       "    fig.message.textContent = msg['message'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_draw = function(fig, msg) {\n",
       "    // Request the server to send over a new figure.\n",
       "    fig.send_draw_message();\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_image_mode = function(fig, msg) {\n",
       "    fig.image_mode = msg['mode'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.updated_canvas_event = function() {\n",
       "    // Called whenever the canvas gets updated.\n",
       "    this.send_message(\"ack\", {});\n",
       "}\n",
       "\n",
       "// A function to construct a web socket function for onmessage handling.\n",
       "// Called in the figure constructor.\n",
       "mpl.figure.prototype._make_on_message_function = function(fig) {\n",
       "    return function socket_on_message(evt) {\n",
       "        if (evt.data instanceof Blob) {\n",
       "            /* FIXME: We get \"Resource interpreted as Image but\n",
       "             * transferred with MIME type text/plain:\" errors on\n",
       "             * Chrome.  But how to set the MIME type?  It doesn't seem\n",
       "             * to be part of the websocket stream */\n",
       "            evt.data.type = \"image/png\";\n",
       "\n",
       "            /* Free the memory for the previous frames */\n",
       "            if (fig.imageObj.src) {\n",
       "                (window.URL || window.webkitURL).revokeObjectURL(\n",
       "                    fig.imageObj.src);\n",
       "            }\n",
       "\n",
       "            fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n",
       "                evt.data);\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        }\n",
       "        else if (typeof evt.data === 'string' && evt.data.slice(0, 21) == \"data:image/png;base64\") {\n",
       "            fig.imageObj.src = evt.data;\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        var msg = JSON.parse(evt.data);\n",
       "        var msg_type = msg['type'];\n",
       "\n",
       "        // Call the  \"handle_{type}\" callback, which takes\n",
       "        // the figure and JSON message as its only arguments.\n",
       "        try {\n",
       "            var callback = fig[\"handle_\" + msg_type];\n",
       "        } catch (e) {\n",
       "            console.log(\"No handler for the '\" + msg_type + \"' message type: \", msg);\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        if (callback) {\n",
       "            try {\n",
       "                // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n",
       "                callback(fig, msg);\n",
       "            } catch (e) {\n",
       "                console.log(\"Exception inside the 'handler_\" + msg_type + \"' callback:\", e, e.stack, msg);\n",
       "            }\n",
       "        }\n",
       "    };\n",
       "}\n",
       "\n",
       "// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas\n",
       "mpl.findpos = function(e) {\n",
       "    //this section is from http://www.quirksmode.org/js/events_properties.html\n",
       "    var targ;\n",
       "    if (!e)\n",
       "        e = window.event;\n",
       "    if (e.target)\n",
       "        targ = e.target;\n",
       "    else if (e.srcElement)\n",
       "        targ = e.srcElement;\n",
       "    if (targ.nodeType == 3) // defeat Safari bug\n",
       "        targ = targ.parentNode;\n",
       "\n",
       "    // jQuery normalizes the pageX and pageY\n",
       "    // pageX,Y are the mouse positions relative to the document\n",
       "    // offset() returns the position of the element relative to the document\n",
       "    var x = e.pageX - $(targ).offset().left;\n",
       "    var y = e.pageY - $(targ).offset().top;\n",
       "\n",
       "    return {\"x\": x, \"y\": y};\n",
       "};\n",
       "\n",
       "/*\n",
       " * return a copy of an object with only non-object keys\n",
       " * we need this to avoid circular references\n",
       " * http://stackoverflow.com/a/24161582/3208463\n",
       " */\n",
       "function simpleKeys (original) {\n",
       "  return Object.keys(original).reduce(function (obj, key) {\n",
       "    if (typeof original[key] !== 'object')\n",
       "        obj[key] = original[key]\n",
       "    return obj;\n",
       "  }, {});\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.mouse_event = function(event, name) {\n",
       "    var canvas_pos = mpl.findpos(event)\n",
       "\n",
       "    if (name === 'button_press')\n",
       "    {\n",
       "        this.canvas.focus();\n",
       "        this.canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    var x = canvas_pos.x * mpl.ratio;\n",
       "    var y = canvas_pos.y * mpl.ratio;\n",
       "\n",
       "    this.send_message(name, {x: x, y: y, button: event.button,\n",
       "                             step: event.step,\n",
       "                             guiEvent: simpleKeys(event)});\n",
       "\n",
       "    /* This prevents the web browser from automatically changing to\n",
       "     * the text insertion cursor when the button is pressed.  We want\n",
       "     * to control all of the cursor setting manually through the\n",
       "     * 'cursor' event from matplotlib */\n",
       "    event.preventDefault();\n",
       "    return false;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
       "    // Handle any extra behaviour associated with a key event\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.key_event = function(event, name) {\n",
       "\n",
       "    // Prevent repeat events\n",
       "    if (name == 'key_press')\n",
       "    {\n",
       "        if (event.which === this._key)\n",
       "            return;\n",
       "        else\n",
       "            this._key = event.which;\n",
       "    }\n",
       "    if (name == 'key_release')\n",
       "        this._key = null;\n",
       "\n",
       "    var value = '';\n",
       "    if (event.ctrlKey && event.which != 17)\n",
       "        value += \"ctrl+\";\n",
       "    if (event.altKey && event.which != 18)\n",
       "        value += \"alt+\";\n",
       "    if (event.shiftKey && event.which != 16)\n",
       "        value += \"shift+\";\n",
       "\n",
       "    value += 'k';\n",
       "    value += event.which.toString();\n",
       "\n",
       "    this._key_event_extra(event, name);\n",
       "\n",
       "    this.send_message(name, {key: value,\n",
       "                             guiEvent: simpleKeys(event)});\n",
       "    return false;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.toolbar_button_onclick = function(name) {\n",
       "    if (name == 'download') {\n",
       "        this.handle_save(this, null);\n",
       "    } else {\n",
       "        this.send_message(\"toolbar_button\", {name: name});\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.toolbar_button_onmouseover = function(tooltip) {\n",
       "    this.message.textContent = tooltip;\n",
       "};\n",
       "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Pan axes with left mouse, zoom with right\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n",
       "\n",
       "mpl.extensions = [\"eps\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\"];\n",
       "\n",
       "mpl.default_extension = \"png\";var comm_websocket_adapter = function(comm) {\n",
       "    // Create a \"websocket\"-like object which calls the given IPython comm\n",
       "    // object with the appropriate methods. Currently this is a non binary\n",
       "    // socket, so there is still some room for performance tuning.\n",
       "    var ws = {};\n",
       "\n",
       "    ws.close = function() {\n",
       "        comm.close()\n",
       "    };\n",
       "    ws.send = function(m) {\n",
       "        //console.log('sending', m);\n",
       "        comm.send(m);\n",
       "    };\n",
       "    // Register the callback with on_msg.\n",
       "    comm.on_msg(function(msg) {\n",
       "        //console.log('receiving', msg['content']['data'], msg);\n",
       "        // Pass the mpl event to the overridden (by mpl) onmessage function.\n",
       "        ws.onmessage(msg['content']['data'])\n",
       "    });\n",
       "    return ws;\n",
       "}\n",
       "\n",
       "mpl.mpl_figure_comm = function(comm, msg) {\n",
       "    // This is the function which gets called when the mpl process\n",
       "    // starts-up an IPython Comm through the \"matplotlib\" channel.\n",
       "\n",
       "    var id = msg.content.data.id;\n",
       "    // Get hold of the div created by the display call when the Comm\n",
       "    // socket was opened in Python.\n",
       "    var element = $(\"#\" + id);\n",
       "    var ws_proxy = comm_websocket_adapter(comm)\n",
       "\n",
       "    function ondownload(figure, format) {\n",
       "        window.open(figure.imageObj.src);\n",
       "    }\n",
       "\n",
       "    var fig = new mpl.figure(id, ws_proxy,\n",
       "                           ondownload,\n",
       "                           element.get(0));\n",
       "\n",
       "    // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n",
       "    // web socket which is closed, not our websocket->open comm proxy.\n",
       "    ws_proxy.onopen();\n",
       "\n",
       "    fig.parent_element = element.get(0);\n",
       "    fig.cell_info = mpl.find_output_cell(\"<div id='\" + id + \"'></div>\");\n",
       "    if (!fig.cell_info) {\n",
       "        console.error(\"Failed to find cell for figure\", id, fig);\n",
       "        return;\n",
       "    }\n",
       "\n",
       "    var output_index = fig.cell_info[2]\n",
       "    var cell = fig.cell_info[0];\n",
       "\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_close = function(fig, msg) {\n",
       "    var width = fig.canvas.width/mpl.ratio\n",
       "    fig.root.unbind('remove')\n",
       "\n",
       "    // Update the output cell to use the data from the current canvas.\n",
       "    fig.push_to_output();\n",
       "    var dataURL = fig.canvas.toDataURL();\n",
       "    // Re-enable the keyboard manager in IPython - without this line, in FF,\n",
       "    // the notebook keyboard shortcuts fail.\n",
       "    IPython.keyboard_manager.enable()\n",
       "    $(fig.parent_element).html('<img src=\"' + dataURL + '\" width=\"' + width + '\">');\n",
       "    fig.close_ws(fig, msg);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.close_ws = function(fig, msg){\n",
       "    fig.send_message('closing', msg);\n",
       "    // fig.ws.close()\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.push_to_output = function(remove_interactive) {\n",
       "    // Turn the data on the canvas into data in the output cell.\n",
       "    var width = this.canvas.width/mpl.ratio\n",
       "    var dataURL = this.canvas.toDataURL();\n",
       "    this.cell_info[1]['text/html'] = '<img src=\"' + dataURL + '\" width=\"' + width + '\">';\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.updated_canvas_event = function() {\n",
       "    // Tell IPython that the notebook contents must change.\n",
       "    IPython.notebook.set_dirty(true);\n",
       "    this.send_message(\"ack\", {});\n",
       "    var fig = this;\n",
       "    // Wait a second, then push the new image to the DOM so\n",
       "    // that it is saved nicely (might be nice to debounce this).\n",
       "    setTimeout(function () { fig.push_to_output() }, 1000);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_toolbar = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var nav_element = $('<div/>')\n",
       "    nav_element.attr('style', 'width: 100%');\n",
       "    this.root.append(nav_element);\n",
       "\n",
       "    // Define a callback function for later on.\n",
       "    function toolbar_event(event) {\n",
       "        return fig.toolbar_button_onclick(event['data']);\n",
       "    }\n",
       "    function toolbar_mouse_event(event) {\n",
       "        return fig.toolbar_button_onmouseover(event['data']);\n",
       "    }\n",
       "\n",
       "    for(var toolbar_ind in mpl.toolbar_items){\n",
       "        var name = mpl.toolbar_items[toolbar_ind][0];\n",
       "        var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
       "        var image = mpl.toolbar_items[toolbar_ind][2];\n",
       "        var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
       "\n",
       "        if (!name) { continue; };\n",
       "\n",
       "        var button = $('<button class=\"btn btn-default\" href=\"#\" title=\"' + name + '\"><i class=\"fa ' + image + ' fa-lg\"></i></button>');\n",
       "        button.click(method_name, toolbar_event);\n",
       "        button.mouseover(tooltip, toolbar_mouse_event);\n",
       "        nav_element.append(button);\n",
       "    }\n",
       "\n",
       "    // Add the status bar.\n",
       "    var status_bar = $('<span class=\"mpl-message\" style=\"text-align:right; float: right;\"/>');\n",
       "    nav_element.append(status_bar);\n",
       "    this.message = status_bar[0];\n",
       "\n",
       "    // Add the close button to the window.\n",
       "    var buttongrp = $('<div class=\"btn-group inline pull-right\"></div>');\n",
       "    var button = $('<button class=\"btn btn-mini btn-primary\" href=\"#\" title=\"Stop Interaction\"><i class=\"fa fa-power-off icon-remove icon-large\"></i></button>');\n",
       "    button.click(function (evt) { fig.handle_close(fig, {}); } );\n",
       "    button.mouseover('Stop Interaction', toolbar_mouse_event);\n",
       "    buttongrp.append(button);\n",
       "    var titlebar = this.root.find($('.ui-dialog-titlebar'));\n",
       "    titlebar.prepend(buttongrp);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._root_extra_style = function(el){\n",
       "    var fig = this\n",
       "    el.on(\"remove\", function(){\n",
       "\tfig.close_ws(fig, {});\n",
       "    });\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._canvas_extra_style = function(el){\n",
       "    // this is important to make the div 'focusable\n",
       "    el.attr('tabindex', 0)\n",
       "    // reach out to IPython and tell the keyboard manager to turn it's self\n",
       "    // off when our div gets focus\n",
       "\n",
       "    // location in version 3\n",
       "    if (IPython.notebook.keyboard_manager) {\n",
       "        IPython.notebook.keyboard_manager.register_events(el);\n",
       "    }\n",
       "    else {\n",
       "        // location in version 2\n",
       "        IPython.keyboard_manager.register_events(el);\n",
       "    }\n",
       "\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
       "    var manager = IPython.notebook.keyboard_manager;\n",
       "    if (!manager)\n",
       "        manager = IPython.keyboard_manager;\n",
       "\n",
       "    // Check for shift+enter\n",
       "    if (event.shiftKey && event.which == 13) {\n",
       "        this.canvas_div.blur();\n",
       "        event.shiftKey = false;\n",
       "        // Send a \"J\" for go to next cell\n",
       "        event.which = 74;\n",
       "        event.keyCode = 74;\n",
       "        manager.command_mode();\n",
       "        manager.handle_keydown(event);\n",
       "    }\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
       "    fig.ondownload(fig, null);\n",
       "}\n",
       "\n",
       "\n",
       "mpl.find_output_cell = function(html_output) {\n",
       "    // Return the cell and output element which can be found *uniquely* in the notebook.\n",
       "    // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n",
       "    // IPython event is triggered only after the cells have been serialised, which for\n",
       "    // our purposes (turning an active figure into a static one), is too late.\n",
       "    var cells = IPython.notebook.get_cells();\n",
       "    var ncells = cells.length;\n",
       "    for (var i=0; i<ncells; i++) {\n",
       "        var cell = cells[i];\n",
       "        if (cell.cell_type === 'code'){\n",
       "            for (var j=0; j<cell.output_area.outputs.length; j++) {\n",
       "                var data = cell.output_area.outputs[j];\n",
       "                if (data.data) {\n",
       "                    // IPython >= 3 moved mimebundle to data attribute of output\n",
       "                    data = data.data;\n",
       "                }\n",
       "                if (data['text/html'] == html_output) {\n",
       "                    return [cell, data, j];\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    }\n",
       "}\n",
       "\n",
       "// Register the function which deals with the matplotlib target/channel.\n",
       "// The kernel may be null if the page has been refreshed.\n",
       "if (IPython.notebook.kernel != null) {\n",
       "    IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n",
       "}\n"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<img src=\"\" width=\"400\">"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "val_auc\n",
      "LSTM\t0.9592231799355174\n",
      "dense_2\t0.9934404347587437\n",
      "dense\t0.992079216081108\n",
      "ens\t0.9897511921689647\n",
      "dense_fc\t0.9885121683617338\n",
      "conv_1d\t0.9935326797200957\n",
      "val_acc\n",
      "LSTM\t0.8527079100055595\n",
      "dense_2\t0.9268071690087628\n",
      "dense\t0.915250398365516\n",
      "ens\t0.9052798538663991\n",
      "dense_fc\t0.9079990991383432\n",
      "conv_1d\t0.9150237890832851\n",
      "val_recall\n",
      "LSTM\t0.9839301518969273\n",
      "dense_2\t1.0\n",
      "dense\t1.0\n",
      "ens\t0.9965187410040829\n",
      "dense_fc\t1.0\n",
      "conv_1d\t1.0\n"
     ]
    }
   ],
   "source": [
    "plt.figure(figsize = (4,4))\n",
    "model_names = trainig_reulsts.keys()\n",
    "for i, metric in enumerate(['val_auc', 'val_acc', 'val_recall']):\n",
    "    plt.subplot(3,1,i+1)\n",
    "    plt.title(metric)\n",
    "    which = 'trained_models_stats'\n",
    "    plot_metrics = [trainig_reulsts[model_name][which][metric] for model_name in model_names]\n",
    "    plt.boxplot(plot_metrics, labels= model_names)\n",
    "    plt.tight_layout()    \n",
    "    print(metric)\n",
    "    for model_name in model_names:\n",
    "        print(model_name + '\\t' + str(trainig_reulsts[model_name]['stats_best_stats'][metric]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "model_name = 'dense'\n",
    "trained_models = []\n",
    "\n",
    "print_summary_only_once = True\n",
    "best_model_epoch = []\n",
    "trained_models_stats = []\n",
    "trained_models_time_taken = []\n",
    "\n",
    "\n",
    "for i in range(N_train):\n",
    "    tic = time()\n",
    "    model_name = model_name + '_' + str(i)\n",
    "    tensorboard = TensorBoard(log_dir=\"logs/{}\".format(model_name + '_' + str(time())))\n",
    "    callbacks_model = callbacks + [tensorboard]\n",
    "\n",
    "    # generate model\n",
    "    model_input, model_output , _ = dense_model_generator(n_timesteps, n_features)\n",
    "    model = Model(model_input, model_output, name = model_name)\n",
    "    \n",
    "    #compile model\n",
    "    model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy', auc_roc, recall])\n",
    "    if print_summary_only_once:\n",
    "        model.summary()\n",
    "        print_summary_only_once = False\n",
    "    \n",
    "    # train model\n",
    "    model.fit(x_train, \n",
    "              y_train, epochs=epochs, \n",
    "              batch_size=batch_size, \n",
    "              validation_split=validation_split_on_training,\n",
    "              verbose=True,\n",
    "              callbacks = callbacks_model)     \n",
    "    trained_models.append(model)\n",
    "    \n",
    "    # training time\n",
    "    training_time = time()-tic\n",
    "    trained_models_time_taken.append(training_time)\n",
    "    print('training time: {}s'.format(training_time))\n",
    "    \n",
    "    # early stopping epoch\n",
    "    best_epoch = es_cb.stopped_epoch\n",
    "    best_model_epoch.append(best_epoch)\n",
    "    \n",
    "    #append best stat\n",
    "    best_stats = {}\n",
    "    for key in model.history.history.keys():\n",
    "        best_stats[key] = model.history.history[key][best_epoch]\n",
    "    trained_models_stats.append(best_stats)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "model_name = 'dense'\n",
    "tensorboard = TensorBoard(log_dir=\"logs/{}\".format(model_name + '_' + str(time())))\n",
    "callbacks_dense = callbacks + [tensorboard]\n",
    "\n",
    "#generate model\n",
    "dense_input, dense_output , _ = dense_model_generator(n_timesteps, n_features)\n",
    "model = Model(dense_input, dense_output, name = model_name)\n",
    "\n",
    "#compile model\n",
    "model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])\n",
    "model.summary()\n",
    "model.fit(x_train, \n",
    "          y_train, epochs=epochs, \n",
    "          batch_size=batch_size, \n",
    "          validation_split=validation_split_on_training,\n",
    "          verbose=True,\n",
    "         callbacks = callbacks_dense)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "model_name = 'LSTM'\n",
    "tensorboard = TensorBoard(log_dir=\"logs/{}\".format(model_name + '_' + str(time())))\n",
    "callbacks_lstm = callbacks + [tensorboard]\n",
    "\n",
    "lstm_input, lstm_output, _  = lstm_model_generator(n_timesteps, n_features)\n",
    "\n",
    "model = Model(lstm_input, lstm_output, name= model_name )\n",
    "model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])\n",
    "\n",
    "model.fit(x_train, \n",
    "          y_train, epochs=epochs, \n",
    "          batch_size=batch_size, \n",
    "          validation_split=validation_split_on_training,\n",
    "          verbose=True,\n",
    "         callbacks = callbacks_lstm)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Dense network approach"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "some comments about this architecture:\n",
    "\n",
    "- Note that the unstack dim is the feature dimension"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "model_name = 'dense'\n",
    "tensorboard = TensorBoard(log_dir=\"logs/{}\".format(model_name + '_' + str(time())))\n",
    "callbacks_dense = callbacks + [tensorboard]\n",
    "\n",
    "#generate model\n",
    "dense_input, dense_output , _ = dense_model_generator(n_timesteps, n_features)\n",
    "model = Model(dense_input, dense_output, name = model_name)\n",
    "\n",
    "#compile model\n",
    "model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])\n",
    "model.summary()\n",
    "model.fit(x_train, \n",
    "          y_train, epochs=epochs, \n",
    "          batch_size=batch_size, \n",
    "          validation_split=validation_split_on_training,\n",
    "          verbose=True,\n",
    "         callbacks = callbacks_dense)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Hybrid ensemble"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "model_name = 'ens'\n",
    "tensorboard = TensorBoard(log_dir=\"logs/{}\".format(model_name + '_' + str(time())))\n",
    "callbacks_ens = callbacks + [tensorboard]\n",
    "\n",
    "ens_input, ens_output, _  = hibrid_ens_generator(n_timesteps, n_features)\n",
    "\n",
    "\n",
    "model = Model(ens_input, ens_output, name= model_name)\n",
    "model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])\n",
    "model.summary()\n",
    "\n",
    "model.fit(x_train, \n",
    "          y_train, epochs=epochs, \n",
    "          batch_size=batch_size, \n",
    "          validation_split=validation_split_on_training,\n",
    "          verbose=True,\n",
    "         callbacks = callbacks_ens)\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
